GATE DA 2026 · Relational Algebra

MCQ · 2 marks · Problem DBMS-RELM-0058

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\[\begin{array}{|c|c|c|} \hline P & Q & R \\ \hline P1 & Q1 & R1 \\ \hline P2 & Q2 & R2 \\ \hline P3 & Q3 & R2 \\ \hline \end{array}\]Y\[\begin{array}{|c|c|c|} \hline P & Q & S \\ \hline P1 & Q1 & 2 \\ \hline P1 & Q2 & 5 \\ \hline P2 & Q1 & 6 \\ \hline P3 & Q3 & 1 \\ \hline \end{array}\]Z\[\begin{array}{|c|c|} \hline P & T \\ \hline P1 & T1 \\ \hline P3 & T2 \\ \hline P4 & T3 \\ \hline P4 & \text{NULL} \\ \hline \end{array}\]Consider the relational algebra expression\(\prod_{P R S}\left[\left(\sigma_{(Q=Q 3 \vee R=R 2)}[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. A
    Two rows \(\text{(P1, R1, 2)}\) and \(\text{(P1, R1, 5)}\)
  2. B
    Three rows \(\text{(P1, R1, 2), (P1, R1, 5)}\) and \(\text{(P2, R2, 6)}\)
  3. C
    One row \(\text{(P1, R1, 2)}\)
  4. D
    Zero rows

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionStep 1: \(X\bowtie Y\) (natural join on \(P,Q\)): matching \((P,Q)\) pairs present in both: \((P1,Q1)\) and \((P3,Q3)\), giving \(\{(P1,Q1,R1,2),\ (P3,Q3,R2,1)\}\). (\((P2,Q2)\) in \(X\) has no matching row in \(Y\).)Applying \(\sigma_{(Q=Q3\vee R=R2)}\): row \((P1,Q1,R1,2)\) fails both conditions (excluded); row \((P3,Q3,R2,1)\) satisfies \(Q=Q3\) (included). Result: \(\{(P3,Q3,R2,1)\}\) — one row.Step 2: \(Y\bowtie Z\) (natural join on \(P\)): \(P1\) matches twice (\((P1,Q1,2,T1)\), \((P1,Q2,5,T1)\)), \(P3\) matches once (\((P3,Q3,1,T2)\)). (\(P2\) and \(P4\) don't have matches on both sides.)Applying \(\sigma_{(S>1)}\): keeps \((P1,Q1,2,T1)\) and \((P1,Q2,5,T1)\) (both \(S>1\)); drops \((P3,Q3,1,T2)\) (since \(S=1\), not \(>1\)).Step 3: Join the two filtered results (common attributes \(P,Q,S\)): the first filtered set has \((P,Q,S)=(P3,Q3,1)\); the second has \((P1,Q1,2)\) and \((P1,Q2,5)\). None of these \((P,Q,S)\) combinations match across the two sets (different \(P\) values entirely) — so the final join produces no rows at all.Answer: Zero rowsClick Here for Detail SolutionGateOverflow discussion: https://gateoverflow.in/523183/gate-da-2026-question-32

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com