SQL Practice Problem #001

Find users older than 20

Write a SQL query to find users whose age is greater than 20.

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

idnameagecreated_at
1Alice192026-01-03
2Bob242026-01-07
3Chloe202026-02-11

Output

Expected Output

idnameagecreated_at
2Bob242026-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

Related Problems