The GATE Grind

GATE 2026 DA – Question 42

Database Management and Warehousing · Relational algebra, tuple calculus and SQL · 2 marks · Multiple choice

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$.

X: PQR
P1Q1R1
P2Q2R2
P3Q3R2
Y: PQS
P1Q12
P1Q25
P2Q16
P3Q31
Z: PT
P1T1
P3T2
P4T3
P4NULL

Consider the relational algebra expression

$$\Pi_{P,R,S}\left[\left(\sigma_{(Q = Q3 \vee R = R2)}[X \bowtie Y]\right) \bowtie \left(\sigma_{(S > 1)}[Y \bowtie Z]\right)\right]$$

where $\bowtie$ denotes natural join operation.

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

  1. Two rows (P1, R1, 2) and (P1, R1, 5)
  2. Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)
  3. One row (P1, R1, 2)
  4. Zero rows

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) Zero rows

Explanation

$X \bowtie Y$ joins on $P$ and $Q$ and gives (P1, Q1, R1, 2) and (P3, Q3, R2, 1). The selection $Q = Q3 \vee R = R2$ keeps only (P3, Q3, R2, 1). $Y \bowtie Z$ joins on $P$ and gives (P1, Q1, 2, T1), (P1, Q2, 5, T1) and (P3, Q3, 1, T2), and $S > 1$ keeps the first two. The final join is on the common columns $P$, $Q$ and $S$. The left side has $P = P3$ and the right side has only $P = P1$, so nothing matches and the output has zero rows.