Find the three most expensive products

Return product_id, name and price for up to three products with a non-NULL price. Sort by price from highest to lowest, then product_id from lowest to highest to break ties. Use LIMIT 3.

Difficulty: beginner

Show hint

Exclude NULL prices before sorting. ORDER BY can use a different direction for each column.

Tables and sample data

Each test starts with fresh tables. Result row order matters for this challenge. Column names and column order must match.

Sample data: products
product_id (integer)name (text)price (numeric)
1Notebook5
2Monitor220
3Keyboard40
4Desk180
Expected sample result
product_idnameprice
2Monitor220
4Desk180
3Keyboard40

Your solution

SQL · PostgreSQL

Results

PostgreSQL loads when you Run or Submit. Write one read-only SELECT or WITH query. Your query runs in this browser.

Back to Lesson