×

sql · level 3 · unit 1 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

stacks one result on top of another.

A join puts tables side by side. UNION stacks results instead, like adding one list to the bottom of another. Both queries must give the same number of columns, and the column names come from the first query.

UNION throws away repeated rows, so a pupil in two clubs appears once. keeps every row. It is faster, and it is right whenever repeats matter, such as counting sign-ups.

ORDER BY goes once, at the very end, and sorts the whole stack.

SELECT pupil FROM chess
UNION
SELECT pupil FROM choir
ORDER BY pupil;

Ava and Mia are in both clubs, yet each appears only once.