Question:

Consider the given relations \(X\), \(Y\) and \(Z\). The relation \(X\) has three columns P, Q and R. The relation \(Y\) has three columns P, Q and S. The relation \(Z\) has two columns P and T.

Relation X:
PQR
P1Q1R1
P2Q2R2
P3Q3R2

Relation Y:
PQS
P1Q12
P1Q25
P2Q16
P3Q31

Relation Z:
PT
P1T1
P3T2
P4T3
P4NULL


Consider the relational algebra expression
\[ \Pi_{P,R,S}\Big[\big(\sigma_{(Q=Q3 \vee R=R2)}[X \Join Y]\big) \Join \big(\sigma_{(S>1)}[Y \Join Z]\big)\Big] \]
where \(\Join\) denotes natural join operation.

Which of the following options is the correct output for the given expression?

Show Hint

Compute \(X \Join Y\) and \(Y \Join Z\) separately, apply each selection, then check whether the surviving P values on the two sides can ever match before joining them.
Updated On: Jul 22, 2026
  • Two rows (P1, R1, 2) and (P1, R1, 5)
  • Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)
  • One row (P1, R1, 2)
  • Zero rows
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Join X and Y on their shared columns.
X and Y share the columns P and Q, so \(X \Join Y\) keeps only rows where both P and Q match.
X(P1,Q1,R1) matches Y(P1,Q1,2), giving (P1,Q1,R1,2). X(P2,Q2,R2) has no Y row with P=P2 and Q=Q2 (the only P2 row in Y is Q1), so it drops out. X(P3,Q3,R2) matches Y(P3,Q3,1), giving (P3,Q3,R2,1).
So \(X \Join Y = \{(P1,Q1,R1,2), (P3,Q3,R2,1)\}\).

Step 2: Apply the selection \(Q=Q3 \vee R=R2\).
For (P1,Q1,R1,2): Q is Q1, not Q3, and R is R1, not R2, so the condition is false and this row is dropped.
For (P3,Q3,R2,1): Q is Q3, so the condition is true and this row survives.
So the left branch gives \(\{(P3,Q3,R2,1)\}\).

Step 3: Join Y and Z on their shared column P.
Y(P1,Q1,2) matches Z(P1,T1), giving (P1,Q1,2,T1). Y(P1,Q2,5) also matches Z(P1,T1), giving (P1,Q2,5,T1). Y(P2,Q1,6) has no Z row with P=P2, so it drops. Y(P3,Q3,1) matches Z(P3,T2), giving (P3,Q3,1,T2).
So \(Y \Join Z = \{(P1,Q1,2,T1), (P1,Q2,5,T1), (P3,Q3,1,T2)\}\).

Step 4: Apply the selection \(S>1\).
(P1,Q1,2,T1) has S=2, which is greater than 1, so it stays. (P1,Q2,5,T1) has S=5, so it stays. (P3,Q3,1,T2) has S=1, which is not greater than 1, so it is dropped.
So the right branch gives \(\{(P1,Q1,2,T1), (P1,Q2,5,T1)\}\).

Step 5: Join the two branches.
The left branch has columns P, Q, R, S with the single row P3,Q3,R2,1. The right branch has columns P, Q, S, T. The natural join matches on the shared columns P, Q and S.
The left row has P=P3, but every row on the right has P=P1, so no pair of rows agrees on P. Since P already fails to match, the join has nothing to output.

Step 6: Project and conclude.
Projecting P, R, S on an empty relation still gives an empty relation.
So the final result has zero rows, which is option (D).\[ \boxed{\text{Zero rows}} \]
Was this answer helpful?
0
0

Top GATE DA Data Science and Artificial Intelligence Questions

View More Questions

Top GATE DA Database Management Systems Questions

View More Questions