Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q46 — Tuple Calculus and SQL

Explain with AI

Consider the following database table named top_scorer\text{top\_scorer}.

playercountrygoalsKloseGermany16RonaldoBrazil15G MullerGermany14FontaineFrance13PeleBrazil12KlinsmannGermany11KocsisHungary11BatistutaArgentina10CubillasPeru10LatoPoland10LinekerEngland10T MullerGermany10RahnGermany10top_scorer\overset{\text{top\_scorer}}{\begin{array}{|c|c|c|}\hline\\ \textbf{player}& \textbf{country}& \textbf{goals} \\ \hline \text{Klose}& \text{Germany}& 16\\ \hline \text{Ronaldo}& \text{Brazil}& 15 \\ \hline \text{G Muller}& \text{Germany}& 14 \\ \hline \text{Fontaine}& \text{France}& 13 \\ \hline \text{Pele}& \text{Brazil}& 12 \\ \hline \text{Klinsmann}& \text{Germany}& 11 \\ \hline \text{Kocsis}& \text{Hungary}& 11 \\ \hline \text{Batistuta}& \text{Argentina}&10 \\ \hline \text{Cubillas}& \text{Peru}&10 \\ \hline \text{Lato}& \text{Poland}& 10 \\ \hline \text{Lineker}& \text{England}& 10 \\ \hline \text{T Muller}& \text{Germany}& 10 \\ \hline \text{Rahn}& \text{Germany}& 10 \\ \hline \end{array}}

Consider the following SQL 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')

The number of tuples returned by the above SQL query is ______

View worked solution

Answer: 7

To find the number of tuples returned by the SQL query, let us analyze the two conditions in the WHERE clause separately.

Condition 1: ta.goals > ALL (...)

The first subquery is:

SELECT tb.goals FROM top_scorer AS tb WHERE tb.country = 'Spain'
  • Looking at the top_scorer table, there are no players from Spain.
  • Therefore, this subquery returns an empty set.
  • In SQL, any comparison of the form value > ALL (empty_set) always evaluates to TRUE.

Thus, Condition 1 is satisfied for all tuples in the table.

Condition 2: ta.goals > ANY (...)

The second subquery is:

SELECT tc.goals FROM top_scorer AS tc WHERE tc.country = 'Germany'
  • The players from Germany and their goals are:
    • Klose: 16
    • G Muller: 14
    • Klinsmann: 11
    • T Muller: 10
    • Rahn: 10
  • So, the subquery returns the set of values: {16, 14, 11, 10}.
  • The operator > ANY means the value must be strictly greater than at least one value in the returned set. Mathematically, this is equivalent to: ta.goals>min⁡({16,14,11,10})\text{ta.goals} > \min(\{16, 14, 11, 10\}) ta.goals>10\text{ta.goals} > 10

Combining the Conditions

Since the query uses an AND operator, both conditions must be true. This simplifies to finding all players with goals > 10:

Player Goals Goals > 10?
Klose16Yes (✔)
Ronaldo15Yes (✔)
G Muller14Yes (✔)
Fontaine13Yes (✔)
Pele12Yes (✔)
Klinsmann11Yes (✔)
Kocsis11Yes (✔)
Batistuta10No
Cubillas10No
Lato10No
Lineker10No
T Muller10No
Rahn10No

The players who satisfy the condition are: Klose, Ronaldo, G Muller, Fontaine, Pele, Klinsmann, and Kocsis.

The total number of tuples returned is 7.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions