Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

SQL is a language intended for table transformation. The input is one or more tables, the output is also a table and every instruction applied in the middle gets and outputs a table. Everything in SQL is about tables.

Tables have columns and columns have a name and a data type: INT, STRING, DATE, BOOLEAN, etc.

Table rows are data records and the intersection with a column is a cell.

The execution order of a SQL is:

FROM → JOIN ON → WHERE → SELECT → DISCTINCT → GROUP BY → HAVING → ORDER BY → OFFSET → LIMIT

  1. Everything starts with a FROM table. which is JOINED other tables to produce a new one.

  2. Then the table (1) above is pruned horizontally with WHERE by dropping all the records no matching the conditions

  3. The new table (2) is pruned vertically then, to match the SELECT columns only.

  4. DISTINCT removes all the duplicate records in (3)

  5. GROUP BY will create a new table from (4) grouping by the provide columns.

  6. HAVING will prune the previous (5) table by removing all the records no matching the conditions. HAVE acts similarly to the WHERE clause for the GROUP BY.

  7. The filtered grouped table (6) will be ORDER BY some columns

  8. OFFSET N will skip N first records in (7)

  9. and LIMIT M will take the output table from (8) and remove all the records after the M first ones.

The result of all the above operations (many optional) will output another temporary table that will be destroyed once it has been read.

  • No labels