Skip
Arish's avatar

8. Practice - Filter by Age


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

idnameagecoursemarksgrade
2Bob12JavaScript78B
5Eve12Python88A

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

TypeExampleQuotes
String'Python'Required
Number12Not required
Date'2024-01-01'Required

Next Steps

We'll learn to filter with inequalities: less than, greater than, and more!