Retrieving Records

It does no good to put records in a database unless you retrieve them eventually and do something with them. That's the purpose of the SELECT statement: to help you get at your data. SELECT is probably the most commonly used statement in the SQL language, but it can also be the trickiest; the constraints you use to choose rows can be arbitrarily complex and can involve comparisons between columns in many tables.

The basic syntax of the SELECT statement looks like this:

SELECT selection_listWhat columns to select
FROM table_list Where to select rows from
WHERE primary_constraintWhat conditions rows must satisfy
GROUP BY grouping_columnsHow to group results
ORDER BYsorting_columnsHow to sort results
HAVINGsecondary_constraintSecondary ...

Get MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.