Skip to content
Official PYQ · 2012

GATE CS 2012 Q51 — Tuple Calculus and SQL

Explain with AI

Consider the following relations A,BA, B and C:C:
 

IdNameAge12Arun6015Shreya2499Rohit11AIdNameAge15Shreya2425Hari4098Rohit2099Rohit11BIdPhoneArea1022000299210001C\overset{\textbf{A}}{\begin{array}{|c|c|c|}\hline\\ \textbf{Id}& \textbf{Name}& \textbf{Age} \\ \hline 12& \text{Arun}& 60 \\ \hline 15& \text{Shreya}& 24 \\ \hline 99& \text{Rohit}& 11 \\ \hline \end{array}}\qquad \overset{\textbf{B}}{\begin{array}{|c|c|c|}\hline\\ \textbf{Id}& \textbf{Name}& \textbf{Age} \\ \hline 15& \text{Shreya}& 24 \\ \hline 25 & \text{Hari} & 40 \\ \hline 98 & \text{Rohit} & 20 \\ \hline 99& \text{Rohit}& 11 \\ \hline \end{array}}\qquad \overset{\textbf{C}}{\begin{array}{|c|c|c|}\hline\\ \textbf{Id}& \textbf{Phone}& \textbf{Area} \\ \hline 10& 2200& 02 \\ \hline 99& 2100& 01\\ \hline \end{array}}

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
View worked solution

Answer: B

To find the number of tuples returned by the SQL query, let us evaluate it step-by-step:

Step 1: Evaluate the Subquery

The subquery is:

SELECT B.Age 
FROM B 
WHERE B.Name = 'Arun'

Looking at relation BB, there is no tuple where the Name attribute is 'Arun'. Therefore, this subquery returns an empty set (∅\emptyset).

Step 2: Evaluate the Outer Query Condition

The outer query filters tuples from relation AA using the condition:

A.Age>ALL (∅)\text{A.Age} > \text{ALL } (\emptyset)

In SQL, the > ALL operator checks if a value is greater than every value in the subquery result. Mathematically, this is a universal quantification:

∀y∈S,A.Age>y\forall y \in S, \text{A.Age} > y

When the set SS is empty (S=∅S = \emptyset), this condition is vacuously true for any value of A.Age. Thus, the WHERE clause evaluates to TRUE for every tuple in relation AA.

Step 3: Count the Resulting Tuples

Since the condition is true for all tuples in AA, the query selects the Id of every tuple in AA:

  • For Id=12\text{Id} = 12, Age=60  ⟹  TRUE\text{Age} = 60 \implies \text{TRUE}
  • For Id=15\text{Id} = 15, Age=24  ⟹  TRUE\text{Age} = 24 \implies \text{TRUE}
  • For Id=99\text{Id} = 99, Age=11  ⟹  TRUE\text{Age} = 11 \implies \text{TRUE}

Relation AA contains exactly 33 tuples. Therefore, the result of the query contains 33 tuples.

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

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions