Day 5. Clauses in SQL Queries

Today's topic is clauses—not the kind that distribute presents during the holidays, but the ones you use with a SELECT statement. By the end of the day, you will understand and be able to use the following clauses:

  • WHERE

  • ORDER BY

  • GROUP BY

  • HAVING

To get a feel for where these functions fit in, examine the general syntax of a SELECT statement:

 SELECT [DISTINCT | ALL] { * | { [schema.]{table | view | snapshot}.* | expr } [ [AS] c_alias ] [, { [schema.]{table | view | snapshot}.* | expr } [ [AS] c_alias ] ] ... } FROM [schema.]{table | view | snapshot}[@dblink] [t_alias] [, [schema.]{table | view | snapshot}[@dblink] [t_alias] ] ... [WHERE condition ] [GROUP BY expr [, expr] ... [HAVING condition] ] [{UNION | UNION ALL ...

Get Sams Teach Yourself SQL in 21 Days, Fourth 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.