Skip to content
Coding

SQL for Beginners

A free SQL course for complete beginners. Ten lessons take you from your first SELECT to a full analysis of a bookshop dataset, and every lesson has queries that run and are checked in your browser. It uses SQLite, and nearly everything carries over to PostgreSQL and MySQL.

SQL for Beginners 10 lessons 3 hours of lessons 80 practice questions Free
The course

Every lesson, in order

Planned as 5 weeks at 4 sessions a week, about 30 minutes each. Each lesson opens here in full; in BiliMind your answers are marked and your flashcards come back before you forget them.

10 topics · 3 hr 8m
0% done
Recommended Alternative Learn anytimeChecked from memory Checked from memoryRead ReadLearning LearningNot started Not started

SQL for Beginners

Start here The finish line
  1. Read how a table is laid out and use SELECT to pull columns out of it.

    • A table is rows (things) and columns (facts about them).
    • `SELECT columns FROM table;` returns the chosen columns for every row.
    • `AS` renames a column or a calculated value.
    • A SELECT only reads: it never changes the table.
  2. Keep only the rows you want with comparisons, AND, OR, IN, BETWEEN and LIKE.

    • `WHERE` keeps only the rows whose condition is true.
    • Text is in single quotes; `=` compares; `<>` means not equal.
    • Use brackets when you mix AND and OR.
    • `BETWEEN` includes both ends; `IN` checks a list; `LIKE` with `%` matches patterns.
  3. Put rows in order, take the top few, and list each value only once.

    • Without `ORDER BY` the row order is not guaranteed.
    • `DESC` reverses a sort; list several columns to break ties.
    • `LIMIT` keeps the first rows, so pair it with `ORDER BY`.
    • `DISTINCT` removes duplicate rows from the result.
  4. Summarize many rows into one with aggregates, then summarize by group with GROUP BY and HAVING.

    • Aggregates (`COUNT`, `SUM`, `AVG`, `MIN`, `MAX`) turn many rows into one value.
    • `GROUP BY` makes one row per group; other selected columns must be grouped or aggregated.
    • `WHERE` filters rows before grouping; `HAVING` filters groups after.
    • `COUNT(*)` counts rows; `COUNT(col)` skips NULLs.
  5. Combine rows from related tables with INNER JOIN and LEFT JOIN.

    • A foreign key stores another table's id; `JOIN ... ON` pairs rows whose keys match.
    • An inner join drops rows with no match; a LEFT JOIN keeps every left-hand row and fills the gaps with NULL.
    • `LEFT JOIN ... WHERE right.id IS NULL` finds rows with nothing related.
    • Use short aliases and write `ON` for every join; `COUNT(right.id)` counts real matches only.
  6. Use one query inside another to compare against a calculated value or a list.

    • A subquery in brackets can supply a single value, a list for `IN`, or a table for `FROM`.
    • `> (SELECT AVG(...))` compares each row with a calculated total.
    • `NOT EXISTS` is safer than `NOT IN` when NULLs are possible.
    • A correlated subquery refers to the outer row and runs per row.
  7. Handle missing values correctly and compute labels with CASE and COALESCE.

    • NULL means unknown: use `IS NULL` and `IS NOT NULL`, never `= NULL`.
    • A WHERE keeps only true rows, so unknown comparisons drop the row.
    • Aggregates skip NULLs; `COUNT(*)` counts rows and `COUNT(col)` counts non-NULL values.
    • `COALESCE` supplies a default, and `CASE` computes a value by rules.
  8. Add, change and remove rows with INSERT, UPDATE and DELETE, and avoid the forgotten WHERE.

    • `INSERT INTO t (cols) VALUES (...)` adds rows; `UPDATE t SET ... WHERE ...` changes them; `DELETE FROM t WHERE ...` removes them.
    • Without WHERE, UPDATE and DELETE affect every row.
    • Preview with a SELECT using the same WHERE before you change anything.
    • Transactions (`BEGIN`, `COMMIT`, `ROLLBACK`) and backups make mistakes recoverable.
  9. Create tables with keys and constraints, and split data so each fact lives in one place.

    • `CREATE TABLE` defines columns, types and rules; constraints (`PRIMARY KEY`, `NOT NULL`, `UNIQUE`, `CHECK`, `DEFAULT`) keep bad data out.
    • A foreign key (`REFERENCES`) ties a row to a row in another table.
    • Keep each fact in one place: one-to-many uses a foreign key, many-to-many uses a junction table.
    • Prefer a simple integer primary key over a name or email.
  10. Answer real business questions with joins, grouping, subqueries and CASE on the whole dataset.

    • Start from the question, then choose tables, joins, filters, grouping and ordering.
    • Filter rows with WHERE before grouping; filter groups with HAVING after.
    • Check a result by recalculating it a second way: two groupings of the same rows must give the same total.
    • Make business rules (such as "shipped only") explicit and apply them in every query.
01Which database does this course use?

SQLite, which runs inside your browser here. The core SQL (SELECT, WHERE, JOIN, GROUP BY, subqueries) is the same in PostgreSQL, MySQL and SQL Server; small details such as date functions differ.

02Do I need to install a database?

No. Every exercise runs in your browser against a small bookshop dataset.

03Do I need to know programming first?

No. SQL is a good first language because you describe what you want rather than how to get it.

04Will I be ready for a data analyst job?

You will have the core skills those jobs test first. Add practice on larger real datasets, and learn a spreadsheet or charting tool next.

05Can I break anything?

No. Each exercise starts from a fresh copy of the data.

Study it properly, free

Start the course in BiliMind and it's yours: 80 questions marked as you go, 47 flashcards on spaced review, a plan around your week, and an assistant that can change any lesson.

Facts checked against: SQLite: SQL language reference, SQLite: datatypes.

See the roadmap for this subject