Problem
Task
Write a SQL query to find users whose age is greater than 20.
Schema
Table Schema
users(id, name, age, created_at)
Input
Sample Data
| id | name | age | created_at |
|---|---|---|---|
| 1 | Alice | 19 | 2026-01-03 |
| 2 | Bob | 24 | 2026-01-07 |
| 3 | Chloe | 20 | 2026-02-11 |
Output
Expected Output
| id | name | age | created_at |
|---|---|---|---|
| 2 | Bob | 24 | 2026-01-07 |
Answer
Check Your Solution
Show Answer and Explanation
Correct Answer
SELECT *
FROM users
WHERE age > 20;
Explanation
The WHERE clause filters rows before they are returned. The condition age > 20 excludes Alice because she is 19 and excludes Chloe because she is exactly 20.
Common Mistakes
- Using age >= 20 when the problem asks for users older than 20.
- Forgetting the WHERE clause and returning every user.
- Putting the condition after ORDER BY instead of before it.
Concepts
Related Concepts
WHERE
Comparison Operators
Filtering Rows
SELECT
Comparison
Next practice