SQL Challenger
All SQL guides

SQL joins explained visually

Switch between INNER, LEFT, RIGHT, and FULL JOIN to see which album and sale rows appear in the result.

Join explorer

Choose a join type

Match albums.id to sales.album_id.

Albums · left side

idtitleResult
1Night BusMatched
2Static BloomOmitted
3Soft CircuitOmitted

Sales · right side

idalbum_idquantityResult
10112Matched
10313Matched
10442Omitted

INNER JOIN result

Keeps only pairs with matching IDs. 2 rows.

album_idtitlesale_idquantity
1Night Bus1012
1Night Bus1033
Show the SQL
WITH album_sample AS (
  SELECT id, title FROM albums WHERE id IN (1, 2, 3)
), sales_sample AS (
  SELECT id, album_id, quantity FROM sales WHERE id IN (101, 103, 104)
)
SELECT a.id AS album_id, a.title, s.id AS sale_id, s.quantity
FROM album_sample AS a
INNER JOIN sales_sample AS s ON a.id = s.album_id
ORDER BY a.id NULLS LAST, s.id;

Why Night Bus appears twice

Album 1 matches sales 101 and 103. A join returns one row for each matching pair, so Night Bus appears on two rows. If you need one row per album, summarize sales by album ID before joining or group the result afterward.

Why sale 104 has no match here

The two input tables show small subsets of the record-shop data. Sale 104 refers to album 4, which is outside this album sample. RIGHT and FULL JOIN keep that sale and fill the missing album columns with NULL.

Read the NULLs from the missing side

Static Bloom and Soft Circuit have no matching sale in this sample. LEFT and FULL JOIN keep them, with NULL in the sale columns. A NULL quantity here means that the join found no sales row for that album.

Try a related challenge