GATE 2019 CS – Question 65
Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V).
| X | Y | Z |
|---|---|---|
| X1 | Y1 | Z1 |
| X1 | Y1 | Z2 |
| X2 | Y2 | Z2 |
| X2 | Y4 | Z4 |
(relation P)
| X | Y | T |
|---|---|---|
| X2 | Y1 | 2 |
| X1 | Y2 | 5 |
| X1 | Y1 | 6 |
| X3 | Y3 | 1 |
(relation Q)
| Y | V |
|---|---|
| Y1 | V1 |
| Y3 | V2 |
| Y2 | V3 |
| Y2 | V2 |
(relation R)
How many tuples will be returned by the following relational algebra query?
$$\Pi_X\left(\sigma_{(P.Y=R.Y\wedge R.V=V2)}(P\times R)\right)-\Pi_X\left(\sigma_{(Q.Y=R.Y\wedge Q.T>2)}(Q\times R)\right)$$
Answer: ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 1
Explanation
**First part:** $\Pi_X\big(\sigma_{P.Y=R.Y\ \wedge\ R.V=V2}(P\times R)\big)$
$R$ rows with $V=V2$: $(Y3,V2)$ and $(Y2,V2)$. $P$ rows whose $Y$ matches: only $(X2,Y2,Z2)$. So the first set is $\{X2\}$.
**Second part:** $\Pi_X\big(\sigma_{Q.Y=R.Y\ \wedge\ Q.T>2}(Q\times R)\big)$
$Q$ rows with $T>2$: $(X1,Y2,5)$ and $(X1,Y1,6)$. Both $Y2$ and $Y1$ appear in $R$. So the second set is $\{X1\}$.
**Difference:** $\{X2\}-\{X1\}=\{X2\}$, which has **1** tuple.
More Relational Model: Relational Algebra, Tuple Calculus, SQL questions
- GATE 2018 CS Q22
- GATE 2018 CS Q51
- GATE 2015 CS (CS1) Q31
- GATE 2015 CS (CS1) Q61
- GATE 2017 CS (CS1) Q33
- GATE 2017 CS (CS1) Q51
All Relational Model: Relational Algebra, Tuple Calculus, SQL questions →