GATE CS 2017 · Set-2 · SQL Queries

NAT · 2 marks · Problem DBMS-SQL-0075

Consider the following database table named top_scorer.\[\begin{array}{|l|l|c|} \hline \text{player} & \text{country} & \text{goals} \\ \hline \text{Klose} & \text{Germany} & 16 \\ \text{Ronaldo} & \text{Brazil} & 15 \\ \text{G Müller} & \text{Germany} & 14 \\ \text{Fontaine} & \text{France} & 13 \\ \text{Pelé} & \text{Brazil} & 12 \\ \text{Klinsmann} & \text{Germany} & 11 \\ \text{Kocsis} & \text{Hungary} & 11 \\ \text{Batistuta} & \text{Argentina} & 10 \\ \text{Cubillas} & \text{Peru} & 10 \\ \text{Lato} & \text{Poland} & 10 \\ \text{Lineker} & \text{England} & 10 \\ \text{T Müller} & \text{Germany} & 10 \\ \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

Numerical answer (NAT).

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{x > \text{ALL}(\varnothing) \text{ is true};\quad x > \text{ANY}(S) \iff x > \min S}\]There is no Spanish player, so the ALL subquery is empty and the first condition holds for every row.German goals are \(\{16, 14, 11, 10, 10\}\), so the ANY condition is goals \(> 10\).Players with more than 10 goals: Klose, Ronaldo, G Müller, Fontaine, Pelé, Klinsmann, Kocsis — \(7\) rows.Answer: 7

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com