GATE CSE 2017 Session 2 Q56: SQL query with >ALL on empty set and >ANY
- Databases
- 2 marks
- NAT
- No negative marking
Syllabus topic: Relational model: relational algebra, tuple calculus and SQL
Question
Consider the following database table named top_scorer, and the SQL query that follows it.
| player | country | goals |
|---|---|---|
| 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 |
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')The number of tuples returned by the above SQL query is ________.
Try it: numerical answer: type the value
Show answer and explanation
Answer: 7 (official GATE 2017 final answer key)
Concept used: A comparison with ALL over an empty subquery result is true for every row, while ANY means greater than the minimum value in the subquery result.
First step: Notice that no row has country 'Spain', so the first condition is always true; then find the smallest goals value among German players.
Full step-by-step solution
Loading…
Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.
More questions on Relational model: relational algebra, tuple calculus and SQL
Every PYQ on this topic →Share this question
Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Databases PYQs
- 2026 Session 1 · Q30Which functional dependency inferences always hold
- 2026 Session 1 · Q31Dependency-preserving decompositions for 1NF, 2NF, 3NF, BCNF
- 2026 Session 1 · Q43Relational algebra equivalent of a tuple calculus join query
- 2026 Session 1 · Q65Number of superkeys with candidate keys {A,B} and {A,C}
- 2026 Session 2 · Q15Match DBMS schema levels with what they describe
- 2026 Session 2 · Q20When two transactions do not conflict on a data item