$ cd ../ (all courses)

SQL

The lingua franca of data. Query anything, anywhere.

⚠ pattern-based checks (code is analyzed, not compiled)

About SQL

SQL (Structured Query Language) is the standard language for relational databases. You'll use it with PostgreSQL (the engine behind Lovable Cloud / Supabase), SQL Server, MySQL, SQLite, and many more. NOTE: Your queries are validated by pattern matching, not executed against a real database. Focus on writing idiomatic, readable SQL. Keywords are case-insensitive in SQL — we accept both UPPER and lower case.

Quick-reference cheat sheet
-- SQL cheat-sheet

-- Read
SELECT col1, col2 FROM table WHERE col1 = 'x' ORDER BY col2 DESC LIMIT 10;

-- Aggregate
SELECT dept, COUNT(*), AVG(salary)
FROM employees
GROUP BY dept
HAVING COUNT(*) > 5;

-- Join
SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON o.user_id = u.id;

-- Write
INSERT INTO users (name, email) VALUES ('Ada', 'ada@x.com');
UPDATE users SET email = 'a@x.com' WHERE id = 1;
DELETE FROM users WHERE id = 1;

-- DDL
CREATE TABLE notes (
  id SERIAL PRIMARY KEY,
  body TEXT NOT NULL,
  created_at TIMESTAMPTZ DEFAULT now()
);

-- CTE + window
WITH ranked AS (
  SELECT *, ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) AS rn
  FROM employees
)
SELECT * FROM ranked WHERE rn = 1;

Tasks

  1. 01
    Hello, SELECT
    Run your first SELECT.
    intro
  2. 02
    SELECT a string
    Return a text literal.
    intro
  3. 03
    Column alias with AS
    Rename an output column.
    intro
  4. 04
    SELECT * FROM table
    Read every column of every row.
    intro
  5. 05
    Select specific columns
    Project only what you need.
    intro
  6. 06
    Filter with WHERE
    Equal to a value.
    intro
  7. 07
    Numeric comparison
    Greater-than filter.
    intro
  8. 08
    AND / OR
    Combine conditions.
    intro
  9. 09
    NOT operator
    Negate a condition.
    intro
  10. 10
    DISTINCT values
    Drop duplicate rows.
    intro
  11. 11
    ORDER BY
    Sort the result.
    easy
  12. 12
    ORDER BY ... DESC
    Newest first.
    easy
  13. 13
    LIMIT n
    Top-N rows (Postgres / MySQL syntax).
    easy
  14. 14
    LIMIT + OFFSET (pagination)
    Page 3 with 10 per page.
    easy
  15. 15
    Pattern match with LIKE
    % wildcard.
    easy
  16. 16
    WHERE ... IN (...)
    Match a set of values.
    easy
  17. 17
    BETWEEN range
    Inclusive range filter.
    easy
  18. 18
    IS NULL
    Find missing values.
    easy
  19. 19
    COUNT(*)
    How many rows?
    easy
  20. 20
    MIN / MAX / AVG
    Three aggregates in one query.
    easy
  21. 21
    GROUP BY
    Aggregate per group.
    easy
  22. 22
    GROUP BY + HAVING
    Filter aggregated groups.
    medium
  23. 23
    String concatenation
    ANSI || operator.
    easy
  24. 24
    LOWER / UPPER
    Case-insensitive matching trick.
    easy
  25. 25
    INNER JOIN
    Match rows in two tables.
    medium
  26. 26
    LEFT JOIN
    Keep all rows from the left table.
    medium
  27. 27
    RIGHT JOIN
    Mirror image of LEFT JOIN.
    medium
  28. 28
    FULL OUTER JOIN
    Keep both sides, NULLs where missing.
    medium
  29. 29
    Self join
    Manager / employee hierarchy.
    medium
  30. 30
    CROSS JOIN
    Cartesian product.
    medium
  31. 31
    Subquery with IN
    Filter by a derived list.
    medium
  32. 32
    EXISTS
    Correlated existence check.
    medium
  33. 33
    Scalar subquery in SELECT
    One value per row from another query.
    medium
  34. 34
    UNION ALL
    Stack two result sets.
    medium
  35. 35
    CASE expression
    Inline if/else inside SELECT.
    medium
  36. 36
    COALESCE & NULLIF
    Default values and NULL conversion.
    medium
  37. 37
    CREATE TABLE
    Define your first table.
    medium
  38. 38
    INSERT a row
    Add data.
    medium
  39. 39
    Multi-row INSERT
    Insert several rows in one statement.
    medium
  40. 40
    UPDATE with WHERE
    Always include a WHERE clause!
    medium
  41. 41
    DELETE with WHERE
    Targeted delete.
    medium
  42. 42
    ALTER TABLE — add column
    Schema evolution.
    medium
  43. 43
    Foreign key constraint
    Enforce referential integrity.
    medium
  44. 44
    UNIQUE + CHECK
    Multiple constraints in one column.
    medium
  45. 45
    CREATE INDEX
    Speed up lookups.
    medium
  46. 46
    CREATE VIEW
    Save a query as a virtual table.
    medium
  47. 47
    WITH (Common Table Expression)
    Name a subquery for readability.
    hard
  48. 48
    Window — ROW_NUMBER()
    Rank rows inside partitions.
    hard
  49. 49
    RANK vs DENSE_RANK
    Two ways to break ties.
    hard
  50. 50
    Running total with SUM() OVER
    Cumulative aggregate.
    hard
  51. 51
    LAG / LEAD
    Compare to previous / next row.
    hard
  52. 52
    Transactions
    All-or-nothing money transfer.
    hard
  53. 53
    Upsert (ON CONFLICT)
    INSERT or UPDATE in one shot (Postgres).
    hard
  54. 54
    JSON access (Postgres ->>)
    Read a key out of a JSONB column.
    hard
  55. 55
    Row Level Security (Postgres / Supabase)
    Lock down a table.
    hard
  56. 56
    Trigger to keep updated_at fresh
    Function + BEFORE UPDATE trigger.
    hard
  57. 57
    Recursive CTE
    Walk a hierarchy.
    hard
  58. 58
    EXPLAIN ANALYZE
    Inspect a query plan.
    hard
  59. 59
    MERGE (SQL Server / Postgres 15+)
    Standard upsert with MERGE.
    hard
  60. 60
    Capstone — Blog schema with RLS
    Build a complete table, index, trigger and policy.
    hard