Skip to content
/ Chapter 9 · Query Debugging and Common Mistakes
Lesson 9.2 · garden_shop
Lesson 9.2

Debugging SQL Queries Step by Step

When a query surprises you, shrink it. Inspect the data, check one piece at a time, and the bug surfaces.

Not every bug throws an error. Sometimes a query runs perfectly and returns nothing, which is its own kind of clue. The fix is to debug in small steps: strip the query back, look at the actual data, and add conditions one at a time.

The query below expects shipped orders but comes back empty. Before changing it blindly, inspect what's really in the status column. String comparisons are case-sensitive, so a capital letter is all it takes to match nothing.

Pattern
-- when a result is empty, inspect the real values:
select distinct status from orders;

-- ...then fix the filter to match
Schema · Garden Shop Table · orders 6 columns · 24 rows
Table · orders

One row per order. Unshipped orders have a null shipped_date.

6 columns · 24 rows
order_id int customer_id int order_date date shipped_date date status text coupon_code text
Your task

The starter returns zero rows. Figure out why, then fix it so it lists every shipped order: order_id and status, sorted by order_id.

·

Run your query to inspect the result.

Expected answer
  • Columns: order_id, status.
  • Rows: 17 shipped orders.
  • String comparisons are case-sensitive, so 'Shipped' matched nothing.