GATE / CS ARCHIVE

GATE CSE 2017 SET 2 / QUESTION 46

GATE CSE 2017 Set 2 Q46

Database Management Systems · SQL & Queries · Full GATE CSE 2017 Set 2 paper

GATE 2017 Set 2, Q46 2 marks · NAT
Report issue

SQL & Queries

Question 46, GATE 2017: top_scorer(player,country,goals) rows: Klose,Germany,16; Ronaldo,Brazil,15; G Müller,Germany,14; Fontaine,France,13; Pelé,Brazil,12; Klinsmann,Germany,11; Kocsis,Hungary,11; Batistuta,Argentina,10; Cubillas,Peru,10; Lato,Poland,10; Lineker,England,10; T Müller,Germany,10; Rahn,Germany,10. Query: SELECT ta.player FROM top_scorer AS ta WHERE ta.goals > ALL (SELECT tb.goals FROM top_scorer AS tb WHERE tb.country='Spain') AND ta.goals > ANY (SELECT tc.goals FROM top_scorer AS tc WHERE tc.country='Germany'). How many tuples result?
Tap to enlarge
Answer & solution

Official answer: 7.0

Our answer: 7

1. The Spain subquery returns no rows. A comparison quantified by ALL over an empty set is true, because there is no counterexample. Hence the first predicate eliminates none of the outer rows.

2. The Germany subquery returns goals 16,14,11,10,10. The >ANY condition requires exceeding at least one of them, so with these non-NULL values it is equivalent to goals>10, not goals>16.

3. Seven rows have goal counts above 10: 16,15,14,13,12,11,11. They yield Klose,Ronaldo,G Müller,Fontaine,Pelé,Klinsmann,Kocsis, so the result has 7 tuples. The query does not say DISTINCT, but these seven selected player values are distinct anyway. Empty ALL and empty ANY behave differently.

Original paper, page 19 · Answer key