Products Without Sales

Given the product and invoice details for products at an online store, find all the products that were not sold. For each such product, display its SKU and product name. Order the result by SKU, ascending.

Schema

There are 2 tables: PRODUCT, INVOICE_ITEM.

PRODUCT
NameTypeDescription

id

int

PK

sku

varchar(32)

 

product_name

varchar(128)

 

product_description

varchar(255)

 

current_price

decimal(8,2)

 

quantity_in_stock

decimal(8,2)

 

is_active

int

 

 

INVOICE_ITEM
NameTypeDescription

invoice_id

int

FK

product_id

int

FK

quantity

decimal(8,2)

 

price

decimal(8,2)

 

line_total_price

decimal(8,2)

 

Note: invoice_item.product_id references product.id

Sample Data Tables
PRODUCT
idskuproduct_nameproduct_descriptioncurrent_pricequantity_in_stockis_active
1330120Game Of Thrones – URBAN DECAYGame Of Thrones Eyeshadow Palette651221
2330121Advanced Night Repair – ESTÉE LAUDERAdvanced Night Repair Synchronized Recovery Complex II98511
3330122Rose Deep Hydration – FRESHRose Deep Hydration Facial Toner45341
4330123Pore-Perfecting Moisturizer – TATCHAPore-Perfecting Moisturizer & Cleanser Duo253931
5330124Capture Youth – DIORCapture Youth Serum Collection95741
6330125Slice of Glow – GLOW RECIPESlice of Glow Set45401
7330126Healthy Skin – KIEHL’S SINCE 1851Healthy Skin Squad681541
8330127Power Pair! – IT COSMETICSIT’s Your Skincare Power Pair! Best-Selling Moisturizer & Eye Cream Duo8000
9330128Dewy Skin Mist – TATCHALimited Edition Dewy Skin Mist Mini202811
10330129Silk Pillowcase – SLIPSilk Pillowcase Duo + Scrunchies Kit17001

 

INVOICE_ITEM
idinvoice_idproduct_idquantitypriceline_total_price
11120651300
217268136
315101001000
43102180360
541565325
6421095950
7454100400
8510100959500
964625150

Product ID’s 1, 2, 4, 5, 7, and 10 had sales. Product ID’s 3, 6, 8 and 9 did not. The expected return is

330122 Rose Deep Hydration - FRESH
330125 Slice of Glow - GLOW RECIPE
330127 Power Pair! - IT COSMETICS
330128 Dewy Skin Mist - TATCHA

SOLUTION:

				
					SELECT p.sku, p.product_name
FROM PRODUCT p
LEFT JOIN INVOICE_ITEM i ON p.id = i.product_id
WHERE i.product_id IS NULL
ORDER BY p.sku ASC;