Exams › GATE › Technical
Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V).
P
X Y Z
X1 Y1 Z1
X1 Y1 Z2
X2 Y2 Z2
X2 Y4 Z4
Q
X Y T
X2 Y1 2
X1 Y2 5
X1 Y1 6
X3 Y3 1
R
Y V
Y1 V1
Y3 V2
Y2 V3
Y2 V2
How many tuples will be returned by the following relational algebra query?
πX (σ(P.Y=R.Y ∧ R.V=V2)(P × R)) − πX (σ(Q.Y=R.Y ∧ Q.T>2)(Q × R))
- 1
- 2
- 3
- 4
Correct answer: 1
Solution
The query first retrieves tuples from the Cartesian product of P and R where P.Y matches R.Y and R.V equals V2, resulting in one matching tuple. Then, it excludes tuples from the Cartesian product of Q and R where Q.Y matches R.Y and Q.T is greater than 2, which yields no tuples to exclude. Thus, the final result contains only one tuple.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →