Module 2: Your first queries

Ask the database questions with SELECT: pick columns, filter rows with WHERE, handle NULL and sort the answer.

  1. SELECT: columns, expressions, aliases, DISTINCT: SELECT picks columns and computes expressions; AS names them; DISTINCT removes rows equal in every selected column.
  2. WHERE: filtering rows: WHERE keeps rows where the condition is true; AND binds before OR, so bracket them; BETWEEN includes both ends; ILIKE ignores case.
  3. NULL: the value that isn't there: NULL means unknown: any comparison with it is unknown, WHERE drops unknown rows, so test with IS NULL and fill gaps with COALESCE.
  4. ORDER BY, LIMIT and pages: ORDER BY sorts (ASC default; Postgres puts NULLs last in ASC, first in DESC); add a tie-breaker; LIMIT n OFFSET (p−1)×n gives page p.

Ends with a 14-question checkpoint (80% passes) and a project: The placement shortlist.