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.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.