Skip to main contentSkip to solution

Consider the following table:

NameClassDOBGenderCityMarks
RohanXI2008MDelhi85
PriyaXII2006FMumbai92
AnkitXI2007MDelhi88
NidhiXII2006FMumbai90
AaravIX2009MKolkata78
SimranXI2007FChandigarh94
RahulXII2006MPune80

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

✅ Correct Option: 4

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question