GATE / CS ARCHIVE

GATE CSE 2012 / QUESTION 51

ALL over an empty SQL subquery

Database Management Systems · SQL & Queries · Full GATE CSE 2012 paper

GATE 2012, Q51 2 marks · MCQ
Report issue

SQL & Queries

Question 51, GATE 2012: Relations: A(Id,Name,Age)={(12,Arun,60),(15,Shreya,24),(99,Rohit,11)}; B(Id,Name,Age)={(15,Shreya,24),(25,Hari,40),(98,Rohit,20),(99,Rohit,11)}; C(Id,Phone,Area)={(10,2200,02),(99,2100,01)}.
How many tuples result from this SQL query?
SELECT A.Id FROM A WHERE A.Age > ALL (SELECT B.Age FROM B WHERE B.Name='Arun');
(A) 4 (B) 3 (C) 0 (D) 1.
Question 51, GATE 2012: Relations: A(Id,Name,Age)={(12,Arun,60),(15,Shreya,24),(99,Rohit,11)}; B(Id,Name,Age)={(15,Shreya,24),(25,Hari,40),(98,Rohit,20),(99,Rohit,11)}; C(Id,Phone,Area)={(10,2200,02),(99,2100,01)}.
How many tuples result from this SQL query?
SELECT A.Id FROM A WHERE A.Age > ALL (SELECT B.Age FROM B WHERE B.Name='Arun');
(A) 4 (B) 3 (C) 0 (D) 1.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

There is no B row with Name=Arun, so the inner query returns an empty relation. A comparison quantified by ALL over an empty set is true: there is no counterexample. Consequently all three rows of A satisfy the WHERE condition, returning Id values 12, 15, 99. The count is 3, B.

Check: ALL means every returned value satisfies the comparison, not that at least one value exists. NOT EXISTS a violating subquery row is true when there are no subquery rows at all. ANY would have the opposite empty-set truth value, false.

Original paper, page 14 · Answer key