SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Amazon: Frequently Bought Together

Unsolved

Amazon recommendation algorithms power the 'Frequently Bought Together' widget on product detail pages. Write a SQL query to identify all distinct pairs of products that appear together in the same order at least 3 times. To prevent duplicates and self-pairs: return each pair only once with `product_1 < product_2`, and never pair a product with itself. Return `product_1`, `product_2`, and `pair_count`. Order the results by `pair_count DESC`, then `product_1 ASC`, and `product_2 ASC`.

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:
🏢 Amazon

Submission History

Your recent query executions and answer checks

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