INTERACTIVE LECTURES
CASE & UNION: one report, many sources
Guided class activity · apply the ideas from the full SQL lessons.
Preparing for Lab 9 · After practice, try the team challenge.
Opening your saved work…
Sign in to save across devices → · Download your guest work before switching accounts.
Make the first matching rule the right rule
Step 1 of 8 · Database: Boreal Board Game Café
READ & UNDERSTAND
Write the business rule in plain language before translating it. A searched CASE tests WHEN conditions in order and returns the first true branch. A more general condition placed first can swallow a more specific one; successful execution will not warn you.
For this practice, a game that needs at least 90 minutes requires a Long slot; at least 45 minutes needs a Standard slot; anything shorter needs a Short slot. Test 44, 45, 89 and 90 on paper. The boundary values matter as much as typical values.
Use simple CASE when comparing one expression to fixed values: CASE tier WHEN 'Gold' THEN 'Gold member' WHEN 'Silver' THEN 'Silver member' ELSE 'Other tier' END. Use searched CASE for ranges or multiple columns. These practice labels are separate from the official lab rules.
Worked example
SELECT title, play_minutes, CASE WHEN play_minutes >= 90 THEN 'Long slot' WHEN play_minutes >= 45 THEN 'Standard slot' ELSE 'Short slot' END AS slot FROM games WHERE id <= 6 ORDER BY id;
Catan satisfies both numeric tests. The first match assigns Long slot before the broader Standard slot condition can run.
The practice removes the sample filter and preserves one row per game. CASE supplies a column; it does not filter rows.
Your question
For all games, return id, title and slot using Long slot at 90+ minutes, Standard slot at 45+ minutes, otherwise Short slot. Order by id.
Explain your evidence
Which existing game proves that reversing the two WHEN clauses changes the answer? Explain why the row still looks plausible.
Try a query to unlock the worked-answer discussion.
Query results
Predict the result, then run your query.Predict the result, then run your query.
Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.
Explore this query freely in the playground ↗Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.