02, 12 chapters
one table
everything.basics
one table
SELECT, WHERE, NULL, ORDER BY and GROUP BY. everything you can ask of a single table.
- 02.01picking columnscolumns, expressions, aliases, built-in functions, and when SELECT * stops being harmless.
- 02.02filtering with WHEREcomparisons, AND, OR, NOT, BETWEEN and IN. and the missing parentheses around an OR.
- 02.03NULL and three-valued logictrue, false and unknown. why NULL = NULL isn't true, and how WHERE quietly drops rows.
- 02.04sorting with ORDER BYASC, DESC, NULLS FIRST, and why a table has no order until you ask for one.
- 02.05LIMIT, OFFSET and FETCH FIRSTthe first n rows, WITH TIES, and why LIMIT without ORDER BY is a coin toss.
- 02.06DISTINCT and DISTINCT ONthrowing away duplicates, and postgres's keep-one-row-per-group trick.
- 02.07CASE, COALESCE and NULLIFif/else inside an expression, and the two shortcuts you'll type every week.
- 02.08LIKE, ILIKE and regular expressionswildcards, escapes, ~ and ~*. and the case-sensitivity surprise in the C collation.
- 02.09the order a query actually runs inFROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY, LIMIT. the most important picture in SQL.
- 02.10aggregate functionscount(*), count(col) and count(DISTINCT col) count three different things.
- 02.11GROUP BYrows into buckets, one answer per bucket. why every selected column must be grouped or aggregated.
- 02.12HAVINGWHERE for groups. the filter that runs after aggregation, and the one that should have been a WHERE.