Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Products Bought Together

Hard Joins

Return all pairs of products that appear in the same order, with the number of orders in which they appear together. Output the pair with the smaller product_id first, ordered by count descending then product ids.

Table schema

OrderItems(order_id INT, product_id INT)

Sample data

order_id | product_id
1 | 10
1 | 20
2 | 10
2 | 20
2 | 30
3 | 20
3 | 30

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.