← All SQL interview questions
Products that have never been ordered
MediumJoins — Left/Right Outer JoinFlipkartMyntra
A catalogue clean-up needs the dead weight: products with zero order lines ever.
Return sku, product_title and category from catalog_items for every product that has no matching row in order_lines.
Sample data
Table: catalog_items
10 row(s) · showing first 8
| skuTEXT | product_titleTEXT | categoryTEXT | list_priceNUMERIC(10,2) |
|---|---|---|---|
| SK-01 | Linen Kurta | Apparel | 1899.00 |
| SK-02 | Copper Bottle | Kitchen | 999.00 |
| SK-03 | Yoga Mat 6mm | Fitness | 1499.00 |
| SK-04 | Beard Trimmer Pro | Grooming | 2299.00 |
| SK-05 | Wall Planter Set | Decor | 1299.00 |
| SK-06 | Bamboo Lunch Box | Kitchen | 799.00 |
| SK-07 | Resistance Bands | Fitness | 649.00 |
| SK-08 | Silk Scarf | Apparel | 1599.00 |
Table: order_lines
12 row(s) · showing first 8
| line_idINT | skuTEXT | quantityINT | ordered_onDATE |
|---|---|---|---|
| 1 | SK-01 | 2 | 2026-01-04 |
| 2 | SK-03 | 1 | 2026-01-06 |
| 3 | SK-01 | 1 | 2026-01-09 |
| 4 | SK-06 | 3 | 2026-01-11 |
| 5 | SK-10 | 2 | 2026-01-14 |
| 6 | SK-03 | 4 | 2026-01-18 |
| 7 | SK-06 | 1 | 2026-01-21 |
| 8 | SK-08 | 1 | 2026-01-25 |
catalog_items
- skuTEXT
- product_titleTEXT
- categoryTEXT
- list_priceNUMERIC(10,2)
order_lines
- line_idINT
- skuTEXT
- quantityINT
- ordered_onDATE
- Step 1: Drive the query from the table you must preserve in full — `catalog_items` — and `LEFT JOIN` the order lines onto it.
- Step 2: Products that were ordered produce one row per order line; products never ordered produce a single row with `NULL`s on the right-hand side.
- Step 3: `WHERE o.line_id IS NULL` keeps only those unmatched products. Test a `NOT NULL` column such as the primary key so the check is unambiguous.
- Step 4: Project only the catalogue columns; nothing from the right table is meaningful in the result.
SELECT c.sku, c.product_title, c.category
FROM catalog_items AS c
LEFT JOIN order_lines AS o
ON o.sku = c.sku
WHERE o.line_id IS NULL;Approach 2 — NOT IN with a guarded subquery
`NOT IN` is readable but returns nothing if the subquery yields any `NULL`, so filter those out explicitly.
SELECT sku, product_title, category
FROM catalog_items
WHERE sku NOT IN (
SELECT sku FROM order_lines WHERE sku IS NOT NULL
);Learn the concept first
Stuck on Joins — Left/Right Outer Join? These free SQL lessons teach it step by step.
More Joins — Left/Right Outer Join questions
Practising alone only goes so far — our live cohorts pair SQL depth with dashboards, agentic analytics projects and mock interviews.
Explore the program