SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Frequently Bought Together Pairs

Unsolved

Apple's online store wants to power a 'Frequently Bought Together' shelf. Find every pair of different products that were purchased together in the same order in at least 2 distinct orders. Each pair must appear only once (do not return both A-B and B-A, and do not pair a product with itself). Return `product_a` and `product_b` (the product names, where product_a is the product with the smaller `product_id`) and `pair_orders` (the number of distinct orders containing both). Order the results by `pair_orders` descending, then by the smaller product's `product_id` ascending, then by the larger product's `product_id` ascending.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Apple🏢 Amazon🏢 Walmart

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM products
Full source dataset
5 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine