Common data questions

Common Data for Questions 50 and 51:

Consider the following relations A, B and C:

Relation A:

Id Name Age
12 Arun 60
15 Shreya 24
99 Rohit 11

Relation B:

Id Name Age
15 Shreya 24
25 Hari 40
98 Rohit 20
99 Rohit 11

Relation C:

Id Phone Area
10 2200 02
99 2100 01

Shared with question 50.

Question

How many tuples does the result of the following SQL query contain?

SELECT A.Id
FROM A
WHERE A.Age > ALL (SELECT B.Age
                   FROM B
                   WHERE B.Name = 'Arun')
Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2012 answer key

Solution

Evaluate SQL > ALL subquery behavior when the inner query produces an empty result set.

  1. Evaluate the subquery:
SELECT B.Age FROM B WHERE B.Name = 'Arun'

Relation BB contains no tuple with Name = 'Arun'. Therefore, the subquery returns the EMPTY SET ∅\emptyset.

  1. In SQL standard semantics, the comparison val > ALL (subquery) is defined as: for all elements yy in the subquery result, val>yval > y.

  2. When the subquery returns an empty set, this universal quantification is vacuously TRUE for all values (there is no element in the subquery that violates the condition).

  3. Consequently, the WHERE condition evaluates to TRUE for every tuple in relation AA.

  4. Relation AA has 3 tuples: (12, Arun, 60), (15, Shreya, 24), and (99, Rohit, 11). All 3 tuples satisfy the condition and their Ids are returned.

  5. Therefore, the query returns 3 tuples, matching option (B).

Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2012 Computer Science and Information Technology (CS)
Question
51 of 65, printed as CS Q.51
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.