SELECT Clause Ordering

This is probably a good time to review the order in which SELECT statement clauses are to be specified. Table 10.2 lists all the clauses we have learned thus far, in the order they must be used.

Table 10.2. SELECT Clauses and Their Sequence
ClauseDescriptionRequired
SELECTColumns or expressions to be returnedYes
FROMTable to retrieve data fromOnly if selecting data from a table
WHERERow-level filteringNo
GROUP BYGroup specificationOnly if calculating aggregates by group
HAVINGGroup-level filteringNo
ORDER BYOutput sort orderNo

Get Sams Teach Yourself SQL in 10 Minutes, Second Edition 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.