Menu

THE MIDNIGHT CODE REVIEW / CASE 01

The orders that
never came back.

Five orders. Two customers on hold. A query meant to find the rest.
Read it like a code review. What does it actually return?

Db2 for i · SQLAbout 60 secondsNo login. No timer.
review.sqlREAD ONLY

The query under review

SELECT o.order_id
FROM orders o
WHERE NOT EXISTS (
  SELECT 1
  FROM holds h
  WHERE h.customer_id = customer_id
)
ORDER BY o.order_id;
Goal: return orders whose customer has no row in holds.
What does the query return?
A nudge, without the answer

Read the equality inside the subquery. Which table supplies each side? Do not assume that an unqualified name refers to the outer query.