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.

Reconcile each source before trusting the report

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

READ & UNDERSTAND

Start a multi-source report with an inclusion rule for each branch. For a member activity report, sessions and registrations have member IDs; café orders include both members and anonymous walk-ins. A customer report may include walk-ins, while a member loyalty report must exclude them.

Count each branch after its filters. With UNION ALL, the total must equal the sum of those branch counts. Equality is necessary but not sufficient: wrong columns, dates or business rules can still produce the expected count.

Keep the three time meanings explicit: session_date records play, order_date records a purchase, registered_date records a signup. event_date is the scheduled event day. Use this audit method when building the official ledger yourself; the point rules and required output stay in the Canvas handout.

Worked example
SELECT 'Session' AS source, COUNT(*) AS records FROM sessions UNION ALL SELECT 'Signup', COUNT(*) FROM registrations UNION ALL SELECT 'Member order', COUNT(*) FROM cafe_orders WHERE member_id IS NOT NULL ORDER BY source;

The example makes every source’s inclusion rule visible before a full ledger is written.

The practice keeps excluded walk-in records visible in the audit even though they do not belong in a member ledger.

Your question

Return source and records for two café populations: Member order for non-NULL member_id, and Walk-in order for NULL member_id. Stack the counts with UNION ALL and sort by source.

Explain your evidence

If the final count reconciles, what additional evidence would you check before approving the report?

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.