Learn with Abdou

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.

Keep real repeat activity visible

Step 6 of 8 · Database: Boreal Board Game Café

READ & UNDERSTAND

UNION removes rows identical across every selected column; UNION ALL retains every row. Duplicates are a property of the selected output, not proof that the source contains duplicate records. Two different sessions can have the same member and day.

Choose the unit of the report first. A list of distinct days needs deduplication; a list of recorded actions should preserve repeats. Add source and source_id when you need to trace each action back to its original table.

For an audit sample, inspect member 3 on 2026-09-12. Repeated sessions and orders are real source records. A source label separates orders from sessions, but alone it cannot distinguish two sessions on that same day. UNION ALL preserves both even when the display columns match.

Worked example
SELECT id, member_id, session_date FROM sessions WHERE member_id = 3 AND session_date = '2026-09-12' ORDER BY id;

The sample query reveals source IDs before any stacking.

The practice adds order IDs and a source label so the four actions can be traced separately.

Your question

Return every session and café order for member 3 on 2026-09-12 as source (Session or Order), source_id and activity_date. Use UNION ALL and order by source, source_id.

Explain your evidence

If source_id is removed, which rows become indistinguishable? Does an identical display mean the member acted only once?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · Boreal Board Game Café

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

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.