Databases

SQL: Talk to databases

Ask your data questions and get answers in milliseconds, like every big app does.

7 chapters · 26 lessons · free

Try a free lesson Create your free account

What you will learn

1. Your first queries

A database is a set of tables. SELECT asks a table for its rows, and you choose which columns come back.

  • Ask the database Try it SELECT columns FROM table; reads rows. * means every column.
  • Pick the columns Exercise Name the columns you want, separated by commas, in the order you want them.
  • The query that would not run Debug SQL errors say near what they got stuck. That word is where to look.
  • Rename and calculate Exercise AS renames a column in the result. Columns can be calculated with + - * /.
  • Quick check Quiz SELECT picks columns, FROM picks the table, AS renames, and every statement ends with ;.

2. Filter with WHERE

Ask only for the rows you need: players from one country, rich players, names that start with S.

  • Players from one country Exercise WHERE filters rows. Text is written in 'single quotes' in SQL.
  • Strong and rich Exercise Combine conditions with AND (both) and OR (either). Numbers have no quotes.
  • The missing quotes Debug Without quotes it is a column name; with 'quotes' it is a value. A very common SQL mistake.
  • Names that start with S Exercise LIKE 'S%' starts with S, '%ow' ends with ow, '%a%' contains a.
  • Quick check Quiz WHERE + comparisons, AND/OR to combine, LIKE with % to search text.

3. Sort, count and group

Top-3 lists, totals and statistics: ORDER BY, LIMIT, COUNT and GROUP BY.

  • The top 3 Exercise ORDER BY column DESC sorts high to low, LIMIT n keeps the first n rows. ORDER BY comes before LIMIT.
  • How many players? Exercise COUNT, SUM, AVG, MIN and MAX turn many rows into one answer.
  • Players per country Exercise GROUP BY makes groups, and the counting functions work on each group.
  • Counting in the wrong place Debug WHERE filters rows before grouping; HAVING filters groups after it.
  • Quick check Quiz ORDER BY, LIMIT, COUNT/SUM/AVG, GROUP BY, HAVING: the tools behind every dashboard.

4. Add, change and remove

INSERT a new player, UPDATE coins, DELETE a cheater, and learn the one mistake that wipes a whole table.

  • A new player joins Exercise INSERT INTO table (columns) VALUES (values); adds a row. A PRIMARY KEY id numbers itself.
  • Pixel buys coins Exercise UPDATE table SET column = value WHERE condition; changes only the rows that match.
  • The update that hit everyone Debug UPDATE or DELETE without WHERE touches every row. Always write the WHERE first.
  • Ban a player Exercise DELETE FROM table WHERE condition; removes rows. There is no undo, so the WHERE matters.
  • Quick check Quiz INSERT adds, UPDATE changes, DELETE removes, and WHERE keeps it all under control.

5. Your own tables, and JOIN

Design tables with CREATE TABLE, and connect tables with JOIN to answer "who bought what?".

  • Create a table Exercise CREATE TABLE name (column TYPE, ...); with INTEGER, TEXT, REAL, PRIMARY KEY and NOT NULL.
  • One value short Debug The number of values must match the number of columns.
  • Who bought what? Exercise JOIN ... ON connects rows from different tables through their ids. table.column says which table a column comes from.
  • Quick check Quiz Design tables with types and keys, split data into tables, and JOIN them back together.

6. SQL exam

Ten questions about everything in this course. Pass with 8 right answers.

  • The SQL exam Exam You can query, filter, sort, count, change and design databases. That is a real job skill.

7. Final project

Design and fill the database for an app of your own, ask it a real question, and send it for review.

  • The database of your app Final project Designing tables, filling them and asking them questions is exactly what backend developers do every day.

How the course works

You learn by doing: each lesson explains one idea, then you write real code in the editor and see the result right away. The first lesson is free to try without an account; sign up to save your progress and continue.

  • Try it

    Change working code and see the result immediately.

  • Exercise

    Complete a task. A checklist confirms each requirement as you type.

  • Debug

    Fix code that is broken on purpose, and learn why it failed.

  • Quiz

    Check your understanding at the end of a chapter.

More in Databases