AnalystPath

Product Pairs Within Price Range

SQLHardSenior level~15 min

Problem

**[Classic — asked at multiple companies]**

Find all **pairs of distinct products** whose price difference is strictly
less than **$50**.

Return `product_1`, `product_2`, and `price_diff`, ordered by product_1 then product_2. Each pair appears only once.

Tables

Example rows — the live problem includes the full dataset.

products
product_idproduct_nameprice

Expected output

Your answer should return 3 rows with the columns product_1, product_2, price_diff.

Starter code (SQL)

SELECT *
FROM products;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions