skip to content
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.

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