SQL guides
One guide per level, with the basics, worked examples, common mistakes and where you will use it at work. Each one links to practice tasks on the same topic.
SQL skills
From your first SELECT to window functions, on data from your job.
One table
Pick columns, filter rows, sort and cut: the queries you write every day.
- SELECT and FROMEvery query starts with two words: SELECT says which columns, FROM says which table.
- Filter rows with WHERESELECT picks columns, WHERE picks rows. Only rows where the condition is true come back.
- Sort with ORDER BY, cut with LIMITRows have no order of their own. ORDER BY sorts them, LIMIT keeps the first few.
- IN, BETWEEN, LIKE and NULLFour filters that make WHERE shorter and safer: lists, ranges, patterns and missing values.
Summaries
Count, add up and average, per group and with group filters.
- COUNT, SUM, AVG, MIN, MAXAggregates turn many rows into one number: how many, how much, on average, the smallest and the largest.
- GROUP BYGROUP BY splits the table into groups and runs the aggregate once per group.
- Filter groups with HAVINGWHERE removes rows before grouping. HAVING removes whole groups after it.
Joins
Combine two tables: matching rows, missing matches, totals per name.
- JOIN two tablesData is split across tables. JOIN puts the matching rows side by side.
- LEFT JOIN and missing matchesLEFT JOIN keeps every row of the table after FROM. No match means NULL on the other side.
- JOIN with GROUP BYJoin first, then group: amounts come from one table, the names you report by from another.
Functions
Labels with CASE, blanks with COALESCE, text and dates.
- CASE and COALESCECASE is SQL’s if this, then that. COALESCE fills empty values.
- Text functionsText functions reshape text in your result. The data in the table does not change.
- DatesDates compare, sort and group like numbers once you know their format.
Subqueries and CTEs
Queries inside queries, and long queries as named steps.
- SubqueriesPut a whole query in brackets where a value or a list would go. The inner one runs first.
- WITH: named steps (CTEs)WITH gives a query a name. Long queries become a list of short, readable steps.
Window functions
Ranks, running totals and comparisons with the row before.
- ROW_NUMBER and RANKA window function adds a value to every row without collapsing the rows.
- Running totals and sharesSUM with OVER keeps every row and puts a total next to it.
- LAG and LEADLAG looks one row back, LEAD one row ahead, in the order you set inside OVER.
Dialects
The same skills in the syntax of the database your company uses: SQL Server, Oracle, PostgreSQL or Snowflake.
SQL Server
T-SQL: TOP, ISNULL, LEN, DATEADD and DATEDIFF.
- TOP, ISNULL and LENMost of your SQL works in SQL Server as it is. A few everyday things are written differently.
- Dates in SQL ServerSQL Server date functions take the unit as a plain word: day, month, year.
Oracle
FETCH FIRST, NVL, ||, ADD_MONTHS, TO_CHAR and EXTRACT.
- FETCH FIRST, NVL and ||Oracle is close to standard SQL, but it has neither LIMIT nor TOP.
- Dates in OracleOracle adds days with plain arithmetic and has functions for months and formats.
PostgreSQL
LIMIT and OFFSET, ILIKE, DATE_TRUNC, EXTRACT and intervals. Also fits Amazon Redshift.
- LIMIT, OFFSET and ILIKEPostgreSQL follows the SQL standard closely and adds a few handy shortcuts.
- Dates in PostgreSQLPostgreSQL handles dates with DATE_TRUNC, EXTRACT and intervals.
Snowflake
QUALIFY, IFF, ILIKE, DATEADD, DATEDIFF and DATE_TRUNC.
- QUALIFY, IFF and ILIKESnowflake accepts standard SQL and adds shortcuts that save a lot of typing.
- Dates in SnowflakeSnowflake date functions look like SQL Server’s, plus DATE_TRUNC.
Questions people ask
In what order should I read the guides?
In the order of the list: one table, summaries, joins, functions, subqueries and CTEs, window functions. Then the dialect of the database you use at work.
Are the examples the same in every database?
The main track uses SQL that works almost everywhere. Where a database differs, the guide says so, and the dialect guides show the exact syntax.
How long does a level take?
The step by step lesson takes about five minutes. A level counts as done after ten right answers in practice.