Skip to content
GATEiit

GATE CSE 2017 Session 2 Q56: SQL query with >ALL on empty set and >ANY

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.

top_scorer
playercountrygoals
KloseGermany16
RonaldoBrazil15
G MüllerGermany14
FontaineFrance13
PeléBrazil12
KlinsmannGermany11
KocsisHungary11
BatistutaArgentina10
CubillasPeru10
LatoPoland10
LinekerEngland10
T MüllerGermany10
RahnGermany10
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

Numerical answer. No negative marking.
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.

Concept notes

Loading notes…

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

WhatsAppDownload image

Source: official GATE 2017 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key