O'Reilly logo

Joe Celko's SQL for Smarties, 5th Edition by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required