Learn SQL, one sip at a time
Short lessons in plain English. Each one explains a single idea, shows a tiny example, and the rows it gives back. Read one, then try it in today's puzzle.
Everything here is free and works in any major database — PostgreSQL, MySQL, SQLite, SQL Server and BigQuery. Whether you're learning SQL online for the first time, brushing up for an interview, or just want a cozier way to practice, pick a topic below and start sipping.
The basics
Filtering rows
- WHEREWHERE keeps only the rows you want
- text values and quotesText values go inside single quotes
- boolean columnsBoolean columns hold TRUE or FALSE
- ANDAND means both tests must pass
- OROR means either test can pass
- ININ checks a column against a list
- BETWEENBETWEEN covers a range of values
- <><> means 'is not this'
- LIKELIKE matches text against a pattern
- NULLAn empty cell is called NULL
- COALESCECOALESCE fills an empty cell with a backup
- datesDates are compared like numbers
- NULL vs. empty textNULL and empty text ('') are not the same
Sorting
Aggregates and grouping
SQL WHERE vs HAVING visual guide
The Cookie Tin Guide: filter rows first, then filter whole groups.
- COUNT(*)COUNT(*) answers 'how many rows?'
- COUNT(DISTINCT ...)COUNT(DISTINCT ...) counts different values
- SUMSUM adds up a whole column
- AVGAVG gives the average of a column
- MIN and MAXMIN and MAX find the smallest and largest
- ROUNDROUND tidies up a number
- GROUP BYGROUP BY gathers matching rows together
- HAVINGHAVING filters the groups
- finding duplicatesFind duplicates with GROUP BY and HAVING
- counting with CASECASE inside COUNT counts only matching rows
Joining tables
SQL JOIN diagram & cheat sheet
FULL OUTER, LEFT, RIGHT and INNER JOIN side by side, with result tables.
- table aliasesA table alias is a short name for a table
- JOINA JOIN connects two tables
- LEFT JOINLEFT JOIN keeps rows with nothing to connect to
- anti-joinAn anti-join finds rows with no match
- RIGHT JOINRIGHT JOIN keeps every row from the second table
- CROSS JOINCROSS JOIN makes every possible pair
- FULL OUTER JOINFULL OUTER JOIN keeps matched and unmatched rows
- self-joinsA self-join connects a table to itself
Combining results
Window functions
Going deeper
- subqueriesA query can hold another query inside it
- EXISTSEXISTS asks 'is there at least one?'
- Rolling dates with CURRENT_DATERolling dates with CURRENT_DATE
- CASECASE turns values into labels
- WITHWITH gives a result a temporary name
- index helps the database find rows fasterAn index helps the database find rows faster
- WHERE vs HAVINGWHERE filters rows; HAVING filters groups
Common questions
- Can I learn SQL online for free here?
- Yes. Every lesson and every daily SQL puzzle is free, with no signup required. Each lesson covers one idea — SELECT, WHERE, JOIN, GROUP BY — with a tiny example and the exact rows it returns.
- How long does each SQL lesson take?
- Each lesson is a single screen: one idea, one small query, one result table. There are no timers and no pressure — read one whenever you have a coffee-break moment.
- I'm a complete beginner. Where should I start?
- Start with SELECT and WHERE in the first section, then work down the page in order. The sections build on each other: filtering rows, then sorting and limiting, then grouping, then joining tables.
- Do these lessons work with my database?
- The lessons teach standard SQL that works in PostgreSQL, MySQL, SQLite, SQL Server and BigQuery. Where a dialect differs, the lesson says so in an 'in the wild' note.