3.1.1  :  SQL: An Overview

For the user, the most important feature of relational databases is the existence of a high-level query language called SQL (=Sequential Query Language), sometimes pronounced as "sequel". Over time we may describe some features of this language, but as there are many excellent texts online available we rather refer to some of these below.

Overview

an SQL query has roughly the following structure (but see below):
SELECT [TOP ...] ...
  FROM ...
 WHERE ...
 [GROUP BY ... ]
 [ORDER BY ...]
For an exact grammar see for example the BNF of the SQL2003 standard. That standard is in general exactly what is supported by a particular database implementation. In this help page we use the publicly available Millennium database for examples. We (try to) use upper case for the SQL keywords, though the language is case-insensitive.

SELECT

The SELECT determines the form of the result by indicating precisely which columns are returned, and possibly under what name.

Return all columns
SELECT *
  FROM snapshots
Return the named columns
SELECT snapnum, lookbackTime
  FROM snapshots
Return the named columns, but rename them
SELECT snapnum as snapshot
,      redshift as z
  FROM snapshots

FROM

WHERE

GROUP BY

ORDER BY

Common Table Expressions