Build Ada's receipt for order 1. Join customers, orders, order_lines, and products so each line shows display_name, order_id, sku, product name, qty, and line_cents (qty times unit_cents). Keep only order 1.
Requirements
Keep every supplied table and seed row unchanged.
Return display_name, order_id, sku, name, qty, and line_cents.
Compute line_cents as qty * unit_cents.
Restrict to order_id = 1.
Order by sku ascending.
Do not use listed_cents for the money column.
Example
Input
Keep the shop tables, then join a receipt for order_id 1.
A receipt is four tables with four jobs. orders names the sale, customers names the person, order_lines names what was sold and the price that applied, products names the display title. listed_cents on the notebook is already 1500; the line still says 1200 because that is the sold price. Multiplying qty by unit_cents gives line_cents without rewriting history. WHERE o.order_id = 1 drops Grace's mug. INNER JOIN is correct here: a receipt line without a product name is a broken catalog, not a row you keep. ORDER BY sku keeps NB-1 before PEN-2.
Why this pattern matters
Receipts mix identity, a sale header, line snapshots, and catalog names. Using today's listed_cents rewrites yesterday's total when marketing changes a price.
Solution walkthrough
Join orders to customers, lines, and products.
Filter order_id = 1.
Compute qty * unit_cents even though listed_cents for NB-1 is 1500.
Order sku so the notebook precedes the pens.
Common mistakes to avoid
Selecting listed_cents as the money.
Omitting the order_id filter and including Grace's mug.
Starting from products and losing the sold qty.
What this exercise teaches
Inner-join a header to its lines
Bring a name from the catalog
Compute a line total from qty and a snapshot price
A PRACTICAL PLAN
Work through Print a receipt from related tables with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.sql.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.sql only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Print a receipt from related tables” teach?
This intermediate SQL exercise focuses on Inner-join a header to its lines, Bring a name from the catalog, Compute a line total from qty and a snapshot price. Its requirements define the exact behavior to implement before you write code.
How should I validate this SQL solution?
Start with the displayed example input and expected output, then test a boundary case suggested by the requirements. Open your-solution.sql and select Run code. The browser creates a fresh isolated SQLite database, executes the complete script, and compares its result rows with the expected report.
When should I open the reference solution?
Attempt Print a receipt from related tables first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.