Chapter 9 · Interview Level
15. Product Pairs in the Same Category
Medium20 XPE-Commerce
Find all pairs of products that belong to the same category. Return the category_id, the name of the first product (product_a), and the name of the second product (product_b). Avoid duplicate pairs by ensuring the first product's id is less than the second's. Sort by category_id, then product_a.
Tables
- PKidINT
- nameTEXT
- FKcategory_id→ categories.idINT
- priceREAL
- costREAL
- stock_quantityINT
- created_atTIMESTAMP
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.