Learn SQL, the same hands-on way

SQL is how analysts get data out of databases. Write real queries against a real database in your browser, and like the Excel lessons, every query is also tested on data you haven’t seen.

0 of 21 lessons done

  1. SELECT

    1. Getting data out with SELECT

    Ask a table for the columns you want.

    Start
  2. WHERE

    2. Filtering rows with WHERE

    Return only the rows that match.

    Start
  3. ORDER BY, LIMIT and DISTINCT

    3. Sorting and limiting

    Put results in order, take the top few, and remove duplicates.

    Start
  4. LIKE, IN, BETWEEN and NULL

    4. Patterns, lists and missing values

    Flexible filters, and how to find what’s missing.

    Start
  5. Aggregate functions

    5. Summaries with COUNT, SUM and AVG

    Turn many rows into one number.

    Start
  6. GROUP BY and HAVING

    6. Grouping with GROUP BY

    A summary for each group, like a PivotTable.

    Start
  7. JOIN

    7. Combining tables with JOIN

    Pull related data together, like a lookup.

    Start
  8. Subqueries and UNION

    8. Subqueries and UNION

    Use one query’s result inside another.

    Start
  9. CASE

    9. Labels and buckets with CASE

    Turn values into categories inside a query.

    Start
  10. Text functions

    10. Working with text

    Change case, join and cut text.

    Start
  11. Arithmetic, ROUND and COALESCE

    11. Calculations and missing values

    Do maths in a query, and handle NULL.

    Start
  12. Self joins

    12. Joining a table to itself

    Find managers, and count their teams.

    Start
  13. Common table expressions

    13. Step by step with WITH

    Break a hard query into named steps.

    Start
  14. Window functions

    14. Rankings and running totals

    Rank rows and add running totals without grouping them away.

    Start
  15. EXISTS

    15. Checking for matches with EXISTS

    Find rows that do, or don’t, have a match elsewhere.

    Start
  16. INTERSECT and EXCEPT

    16. Combining results with INTERSECT and EXCEPT

    Find what two results share, or what one has that the other doesn’t.

    Start
  17. COUNT DISTINCT and GROUP_CONCAT

    17. Counting carefully

    Distinct counts, NULLs in counts, and lists in one cell.

    Start
  18. LAG and LEAD

    18. Comparing with the previous row

    Changes from one row to the next, and year-on-year growth.

    Start
  19. CREATE TABLE and CREATE VIEW

    19. Creating tables and views

    Define tables, add columns, and save queries as views.

    Start
  20. Putting it together

    20. Building reports

    Shares, complete lists and top customers.

    Start
  21. INSERT, UPDATE and DELETE

    21. Changing data

    Add, change and remove rows safely.

    Start