SQL Challenger
0 of 250 complete

Lessons

0 of 250 complete

Saved in this browser

Lesson 74 of 250

Hard

Show which sources contain each channel

Your task

Return every distinct channel appearing in either receipts or shop_orders after trimming spaces and lowercasing. Show channel, in_receipts, and in_orders as 1 or 0 flags. Sort by channel.

A full outer join keeps values even if they occur on only one side.

Sample data

Choose a table
idsold_onamountchannelmetadata
12025-01-0136 ONLINE {"currency":"EUR","tags":["gift","jazz"]}
22025-01-1622Store{"currency":"EUR","tags":["indie"]}
32025-01-3154 online{"currency":"EUR","tags":["returning","bundle"]}
42025-03-0438STORE {"currency":"EUR","tags":[]}
52025-04-0944Online{"currency":"EUR","tags":["indie"]}

Expected output

channelin_receiptsin_orders
marketplace01
online11
store11
Show a hint

Deduplicate each source before a FULL OUTER JOIN. Use COALESCE to get the channel from either side.

Joins and set operations guide

Match rows by a key

A join combines columns horizontally. The condition links sales.album_id to albums.id. If an album has three sale records, a join can return its title three times.

SELECT s.id AS sale_id, a.title, s.quantity
FROM sales AS s
JOIN albums AS a ON a.id = s.album_id;

Preserve rows without a match

A LEFT JOIN retains each album. The quantity condition belongs in ON because it defines which sales qualify as matches. Placing it in WHERE would also remove albums whose sale columns are NULL.

SELECT a.title, s.id AS large_sale_id
FROM albums AS a
LEFT JOIN sales AS s
  ON s.album_id = a.id
 AND s.quantity >= 3;

Combine result sets vertically

UNION stacks compatible result sets and removes duplicate rows. UNION ALL keeps every row. INTERSECT keeps shared rows, and EXCEPT keeps rows unique to the first result. With set operations, both inputs must return the same number of columns.

SELECT title FROM albums WHERE genre = 'Jazz'
UNION
SELECT title FROM albums WHERE price < 20;
SQLiteCtrl / ⌘ + Enter

Press Control+Space for SQL suggestions. Use the arrow keys to select an option and Enter to insert it.

Results

Loading SQLite…