17.1. SELECT and JOINs

There is an order to the execution of the clauses of an SQL SELECT statement that does not seem to be covered in most beginning SQL books. It explains why some things work in SQL and others do not.

17.1.1. One-Level SELECT Statement

The simplest possible SELECT statement is just “SELECT * FROM Sometable;” which returns the entire table as it stands. You can actually write this as “TABLE Sometable” in Standard SQL, but nobody seems to use that syntax. Though the syntax rules say that all you need are the SELECT and FROM clauses, in practice there is almost always a WHERE clause.

Let’s look at the SELECT statement in detail. The syntax for the statement is:

 SELECT [ALL | DISTINCT] <scalar expression list> FROM <table expression> ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.