Exercise: Find Students by Age
Write a query to find all students who are 12 years old.
Task
Select all students where age equals 12.
Solution
sql
1SELECT * FROM students
2WHERE age = 12;Expected Output
| id | name | age | course | marks | grade |
|---|---|---|---|---|---|
| 2 | Bob | 12 | JavaScript | 78 | B |
| 5 | Eve | 12 | Python | 88 | A |
Numeric Comparisons
When filtering by numbers:
sql
1-- No quotes needed for numbers
2SELECT * FROM students WHERE age = 12;
3
4-- This also works but is redundant
5SELECT * FROM students WHERE age = '12';Multiple Age Queries
sql
1-- Students who are 14
2SELECT * FROM students WHERE age = 14;
3
4-- Students who are 15
5SELECT * FROM students WHERE age = 15;
6
7-- Students with marks of 85
8SELECT * FROM students WHERE marks = 85;Key Differences
| Type | Example | Quotes |
|---|---|---|
| String | 'Python' | Required |
| Number | 12 | Not required |
| Date | '2024-01-01' | Required |
Next Steps
We'll learn to filter with inequalities: less than, greater than, and more!
