Consider the following table:
Name Class DOB Gender City Marks Rohan XI 2008 M Delhi 85 Priya XII 2006 F Mumbai 92 Ankit XI 2007 M Delhi 88 Nidhi XII 2006 F Mumbai 90 Aarav IX 2009 M Kolkata 78 Simran XI 2007 F Chandigarh 94 Rahul XII 2006 M Pune 80
Which SQL query would generate the following output from the above table 'STUDENT'?
Name Rohan Priya Ankit Nidhi
(A) SELECT Name FROM STUDENT WHERE Class = 'XI' and Class = 'XII';
(B) SELECT Name FROM STUDENT WHERE NOT Class = 'XI' and Class = 'XII';
(C) SELECT Name FROM STUDENT WHERE City = 'Delhi' and City = 'Mumbai';
(D) SELECT Name FROM STUDENT WHERE City = 'Delhi' or City = 'Mumbai';
Consider the following table:
| Name | Class | DOB | Gender | City | Marks |
|---|---|---|---|---|---|
| Rohan | XI | 2008 | M | Delhi | 85 |
| Priya | XII | 2006 | F | Mumbai | 92 |
| Ankit | XI | 2007 | M | Delhi | 88 |
| Nidhi | XII | 2006 | F | Mumbai | 90 |
| Aarav | IX | 2009 | M | Kolkata | 78 |
| Simran | XI | 2007 | F | Chandigarh | 94 |
| Rahul | XII | 2006 | M | Pune | 80 |
Which SQL query would generate the following output from the above table 'STUDENT'?
| Name |
|---|
| Rohan |
| Priya |
| Ankit |
| Nidhi |
(A) SELECT Name FROM STUDENT WHERE Class = 'XI' and Class = 'XII';
(B) SELECT Name FROM STUDENT WHERE NOT Class = 'XI' and Class = 'XII';
(C) SELECT Name FROM STUDENT WHERE City = 'Delhi' and City = 'Mumbai';
(D) SELECT Name FROM STUDENT WHERE City = 'Delhi' or City = 'Mumbai';
Solution
Rohan and Ankit live in Delhi, and Priya and Nidhi live in Mumbai. Every other student lives in a different city. A row should be selected if its City is Delhi or Mumbai, so the condition needs OR, which is exactly what (D) uses.
(A) and (C): a single column cannot hold two different values in the same row, so Class = 'XI' and Class = 'XII' and City = 'Delhi' and City = 'Mumbai' return no rows.
(B): NOT Class = 'XI' and Class = 'XII' only selects Class XII students (Priya, Nidhi, Rahul), so it misses Rohan and Ankit and wrongly includes Rahul.
Use AND across different conditions that must hold together, and OR when one column may match either of two values.
Related questions:
2025: 21 May Shift 1
2026: 11 May Shift 2