Problem
Task
Return the two products with the highest price.
Schema
Table Schema
products(id, title, category, price)
Input
Sample Data
| id | title | category | price |
|---|---|---|---|
| 1 | Keyboard | Accessories | 49.99 |
| 2 | Monitor | Displays | 219 |
| 3 | Laptop Stand | Accessories | 64 |
Output
Expected Output
| id | title | category | price |
|---|---|---|---|
| 2 | Monitor | Displays | 219 |
| 3 | Laptop Stand | Accessories | 64 |
Answer
Check Your Solution
Show Answer and Explanation
Correct Answer
SELECT *
FROM products
ORDER BY price DESC
LIMIT 2;
Explanation
ORDER BY price DESC puts the highest prices first. LIMIT 2 keeps only the first two rows after sorting.
Common Mistakes
- Using ASC, which returns the cheapest products first.
- Applying LIMIT before sorting conceptually.
- Sorting by id instead of price.
Concepts
Related Concepts
Top N Queries
ORDER BY
LIMIT
Top N
Next practice