GUIDE

How to use this quiz book

Each set holds five questions. Read prerequisites → question → expected output in order, solve it yourself, and only then open the model answer and explanation. Working it out in your head is fine, and so is writing the SQL out. The explanation lets you step through how the tables change at every stage of the query.

01How a session goes

  1. STEP 01Pick a themeIf you are unsure where to start, follow a learning course on the top page.
  2. STEP 02Solve five questionsEvery question carries its own prerequisites and input tables, so everything you need is on the page.
  3. STEP 03Check the explanationThe commented model answer and the table-transition visualizer show why the result looks the way it does.
  4. STEP 04Build a recordMarking a question “Solved” or “Review” updates the catalog, the courses, and the per-theme progress on the top page.

02Reading the catalog

The top page is a heading per theme followed by one row per set. From left to right a row shows volume-part, title, level, and progress.

01 Theme heading The theme name, how many sets it holds, and how far you have come in it.

JOIN8 sets · 5 questions each

02 Level and progress The right edge counts the questions you marked as solved; it lights up blue once all five are done. To its left is the basic / applied level.
03 Volume and part 1-1 is the first five questions of volume 1 and 1-2 the second five. Basic sets come before applied ones.

03Reading a question page

Below is a real question page. The accordions and the visualizer steps work right here.

Example: JOIN BASIC 1-1

01 Five questions per set The top line shows where you are and how many are done. The tabs move between the five questions, marking solved ones with a check and review ones with a bookmark. The thin bar below is the progress of the whole set.
1 / 5 · In progress0 / 5 completed
QUESTION 1

INNER JOIN — Join Two Tables on a Common Key and Keep Only Rows Present in Both

INNER JOINON clauseBasicsIntersection
02 Question heading A one-line title saying what the question teaches, plus keyword tags.
03 Prerequisites The syntax you need in order to solve it. Query shapes and pitfalls always sit immediately before the question.
Background

A JOIN combines two tables horizontally based on a common key column (for example user_id). In a normalized database, user data lives in the users table and order data in the orders table, so a JOIN is required to retrieve related data together.

INNER JOIN is the simplest kind: it keeps only the rows whose key exists in both tables, per the ON clause. Rows whose key exists in just one table are dropped (an intersection).

SELECT columns, ...
FROM   left_table AS alias
INNER JOIN right_table AS alias
  ON left_table.key = right_table.key;
Table aliases (AS o / AS u): a short alias like AS o lets you write o.user_id, making it explicit that you mean "user_id of the orders table". When the same column name exists in several tables, alias qualification is mandatory.
Problem

Join the orders table and the users table on user_id, and retrieve order_id, the user's name (name), and amount (the order amount).

Note: user_id = 4 in orders does not exist in users. And user_id = 3 (Yamada) in users has no orders.

Tables used
▸ orders
order_iduser_idamount
113000
225000
341200
▸ users
user_idname
1Tanaka
2Sato
3Yamada
04 Question and input tables Input data is shown as real tables. The difference between these tables and the expected output is the SQL you are asked for.
05 Expected output The result to aim for. Compare it with your own answer row by row.
Expected Output
order_idnameamount
1Tanaka3000
2Sato5000
Model Answer
SELECT
  o.order_id,
  u.name,      -- the u. prefix states explicitly: the name column of the users table
  o.amount

FROM orders AS o         -- start from orders (the left table)
INNER JOIN users AS u   -- join with users (the right table)
  ON o.user_id = u.user_id  -- match key: keep only rows whose user_id matches in both tables
ORDER BY o.order_id;

/*
  Execution order:
  1. FROM orders AS o        → the orders table
  2. INNER JOIN users AS u   → for each orders row, match and join the users rows satisfying ON
  3. SELECT o.order_id, ...  → project from the joined virtual table
  */
06 Model answer Open it after you have solved the question yourself. Comments explain the intent of each clause and the order of execution.
07 Table-transition visualizer Stepping forward colors which rows and columns are evaluated, what survives, and what drops out. The ← → keys step too.
Explanation (table transitions & key points)
SELECT o.order_id, u.name, o.amount FROM orders AS o INNER JOIN users AS u ON o.user_id = u.user_id;
LEGEND
Rows read / loaded
① FROM
FROM orders AS oRead the orders table (3 rows). The user_id column is the join key. Each of these rows will next be matched against the users table.
1 / 3
order_iduser_idamount
113000
225000
341200
All 3 rows read

On the real page, an illustrated walkthrough of the key points follows below this.

08 Solved and Review Pressing these records the question: the tab check and bookmark marks, the set bar, and the top-page progress all move together.

This figure is not a screenshot: it is built from the same HTML and CSS as a question page. Anything you do here is not saved to your learning record.

04Records and review

Manage your account and learning record →
Get startedBegin with the first set of the “SQL Foundations” course.
Open the first set → Browse all themes