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 returnsnothing, 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 ShopTable · orders6 columns · 24 rows
Table · orders

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

6 columns · 24 rows
order_id intcustomer_id intorder_date dateshipped_date datestatus textcoupon_code text
Your task

The starter returns zero rows. Figure out why, then fix it so it lists everyshipped order: order_id andstatus, sorted by order_id.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: order_id, status.
  • Rows: 17 shipped orders.
  • String comparisons are case-sensitive, so 'Shipped' matched nothing.