There are several components or clauses that make up the select statement. While only one of them is mandatory when using MySQL (the selectclause), you will usually include at least two or three of the six available clauses. Table 3-1 shows the different clauses and their purposes.
Table 3-1. Query clauses
Clause name
Purpose
Select
Determines which columns to include in the query’s result set
From
Identifies the tables from which to draw data and how the tables should be joined
Where
Restricts the number of rows in the final result set
Group by
Used to group rows together by common column values
Having
Restricts the number of rows in the final result set using grouped data
Order by
Sorts the rows of the final result set by one or more columns
All of the clauses shown in Table 3-1 are included in the ANSI specification; additionally, there are several other clauses unique to MySQL that will be explored in Appendix B. The following sections delve into the uses of the six major query clauses.