Chapter 22

Basic SELECT Statement

Abstract

Here is how a SELECT works in SQL … at least in theory. Real products will optimize things, but the code has to produce the same results.

Keywords

WITH

SELECT

FROM

WHERE

GROUP BY

HAVING

“Common Table Expression” (CTE)

RECURSIVE CTE

Here is how a SELECT works in SQL … at least in theory. Real products will optimize things, but the code has to produce the same results.

The high level skeleton for a SELECT is

[WITH < cte list >]
SELECT < column list >
FROM < table constructor >
[WHERE < row search condition >]
[GROUP BY < grouping list >]
[HAVING < group search condition >];

Please note that the only required clauses are SELECT and FROM. The WHERE clause is the most common additional clause. The ...

Get Joe Celko's SQL for Smarties, 5th 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.