Project ForgeSign up free
Database Management Systems
SQL & Transactions
GATE 2017
Hard

Consider a table top_scorer(player, country, goals) with 13 rows, where Germany's rows have goals values {16, 14, 11, 10, 10} and no row has country = 'Spain'. Consider the 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 ____.

7

Explanation

The subquery filtering on country='Spain' returns an EMPTY set (no Spain rows exist). By SQL semantics, a '> ALL (empty set)' comparison is vacuously TRUE for every row (there's nothing in the empty set it could fail to exceed) — so the first condition is always satisfied. The second condition, '> ANY (Germany's goals)', requires ta.goals to exceed at least the SMALLEST value in Germany's goals set {16,14,11,10,10}, i.e. ta.goals > 10. Counting rows with goals > 10 in the full table: 16, 15, 14, 13, 12, 11, 11 — 7 rows qualify.

Source: GATE CS 2017 (Session 2) (2017)

This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.

Start revising free