SQL SELECT with WHERE: Class 12 practice
WHERE keeps only the rows whose condition is true. The quick answer and an example come first; then the method, worked examples and six graded questions.
SQL SELECT with WHERE: quick answer
WHERE keeps only the rows whose condition is true. Combine conditions with AND (both true) and OR (at least one true); BETWEEN a AND b includes both ends.
Example: Table student(name, marks, class): (Asha, 85, 11), (Ravi, 96, 9), (Meera, 93, 11), (Kabir, 67, 11), (Isha, 54, 11), (Arjun, 53, 10). Which names does SELECT name FROM student WHERE marks > 70; return? Answer: Asha, Ravi, Meera.
- Where it is taught: "Database Query using SQL", Class 12 Computer Science.
- On this page: the method, 3 worked examples and 6 graded questions with a full answer key.
How to use this page (about 30 minutes)
- Read the method once, then cover the worked examples and try them yourself before reading the steps.
- Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
- Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
- Write down the mistake behind each wrong answer and redo that question the next day.
What you should know first
- Tables, rows and columns
The idea behind sql select with where
WHERE keeps only the rows whose condition is true. Combine conditions with AND (both true) and OR (at least one true); BETWEEN a AND b includes both ends.
Step-by-step method
- Read the condition carefully.
- Test it row by row.
- Count or list the rows that pass.
Worked example 1 (Basic)
Table student(name, marks, class): (Asha, 85, 11), (Ravi, 96, 9), (Meera, 93, 11), (Kabir, 67, 11), (Isha, 54, 11), (Arjun, 53, 10). Which names does SELECT name FROM student WHERE marks > 70; return?
- Test each row against: marks > 70
- Rows kept: 3
- Answer: Asha, Ravi, Meera
Worked example 2 (Standard)
Table student(name, marks, class): (Asha, 69, 9), (Ravi, 38, 10), (Meera, 44, 11), (Kabir, 64, 11), (Isha, 91, 10), (Arjun, 89, 11), (Zoya, 92, 11), (Dev, 57, 10). Which names does SELECT name FROM student WHERE marks >= 69 AND class = 10; return?
- Test each row against: marks >= 69 AND class = 10
- Rows kept: 1
- Answer: Isha
Worked example 3 (Challenge)
Table student(name, marks, class): (Asha, 94, 11), (Ravi, 92, 9), (Meera, 99, 10), (Kabir, 93, 9), (Isha, 63, 10), (Arjun, 47, 10), (Zoya, 63, 10), (Dev, 85, 9). Which names does SELECT name FROM student WHERE marks BETWEEN 64 AND 84 OR class = 10; return?
- Test each row against: marks BETWEEN 64 AND 84 OR class = 10
- Rows kept: 4
- Answer: Meera, Isha, Arjun, Zoya
Common mistakes and misconceptions
- Treating BETWEEN as exclusive
- Mixing AND with OR
Practice questions
- (Basic) Table student(name, marks, class): (Asha, 56, 10), (Ravi, 83, 10), (Meera, 58, 10), (Kabir, 61, 9), (Isha, 64, 11), (Arjun, 75, 11). Which names does SELECT name FROM student WHERE marks > 69; return?
- (Basic) Table student(name, marks, class): (Asha, 68, 10), (Ravi, 37, 11), (Meera, 42, 11), (Kabir, 45, 9), (Isha, 67, 10), (Arjun, 35, 11). Which names does SELECT name FROM student WHERE marks > 66; return?
- (Standard) Table student(name, marks, class): (Asha, 90, 10), (Ravi, 100, 10), (Meera, 39, 11), (Kabir, 51, 10), (Isha, 94, 9), (Arjun, 78, 9), (Zoya, 62, 9), (Dev, 37, 9). Which names does SELECT name FROM student WHERE marks >= 54 AND class = 9; return?
- (Standard) Table student(name, marks, class): (Asha, 44, 11), (Ravi, 77, 10), (Meera, 39, 10), (Kabir, 74, 11), (Isha, 75, 11), (Arjun, 86, 10), (Zoya, 96, 9), (Dev, 59, 9). Which names does SELECT name FROM student WHERE marks >= 67 AND class = 10; return?
- (Challenge) Table student(name, marks, class): (Asha, 43, 11), (Ravi, 87, 9), (Meera, 55, 9), (Kabir, 37, 10), (Isha, 40, 9), (Arjun, 95, 10), (Zoya, 38, 9), (Dev, 93, 11). Which names does SELECT name FROM student WHERE marks BETWEEN 63 AND 73 OR class = 9; return?
- (Challenge) Table student(name, marks, class): (Asha, 51, 10), (Ravi, 42, 9), (Meera, 68, 10), (Kabir, 84, 10), (Isha, 86, 9), (Arjun, 95, 10), (Zoya, 79, 11), (Dev, 67, 11). Which names does SELECT name FROM student WHERE marks BETWEEN 58 AND 70 OR class = 9; return?
Answer key with full working
- Q1: Test each row against: marks > 69 → Rows kept: 2 → Answer: Ravi, Arjun
- Q2: Test each row against: marks > 66 → Rows kept: 2 → Answer: Asha, Isha
- Q3: Test each row against: marks >= 54 AND class = 9 → Rows kept: 3 → Answer: Isha, Arjun, Zoya
- Q4: Test each row against: marks >= 67 AND class = 10 → Rows kept: 2 → Answer: Ravi, Arjun
- Q5: Test each row against: marks BETWEEN 63 AND 73 OR class = 9 → Rows kept: 4 → Answer: Ravi, Meera, Isha, Zoya
- Q6: Test each row against: marks BETWEEN 58 AND 70 OR class = 9 → Rows kept: 4 → Answer: Ravi, Meera, Isha, Dev
Which textbook this practice follows
This skill is taught under "Database Query using SQL" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Still stuck after the answer key?
If the same step in sql select with where keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).
Related practice and notes
More Class 12 Computer Science practice
Continue with this syllabus
Frequently asked questions
Which chapter is sql select with where in?
This skill is taught under "Database Query using SQL" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.
Which question should I start with?
Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.
How were the answers checked?
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Is this only for CBSE?
The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.
Can I get live help with this topic?
Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.