⌨ Programming Easy SQL Joins

Products That Have Never Been Ordered

Question

Find all products that have never appeared in any order. Return product name and price.

πŸ’‘ Use products and order_items tables with an ANTI JOIN.
SQL Editor
Solution
SELECT
  p.product_name,
  p.price
FROM products p
LEFT JOIN order_items oi ON p.product_id = oi.product_id
WHERE oi.item_id IS NULL
ORDER BY p.product_name;
Explanation: LEFT JOIN order_items to products. WHERE item_id IS NULL filters to products with no matching order line β€” the ANTI JOIN pattern.