Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V). How many…
2019
Consider the following relations P(X,Y,Z), Q(X,Y,T) and R(Y,V).

How many tuples will be returned by the following relational algebra query?
\(\Pi_x (\sigma_{(P.Y=R.Y \wedge R.V=V2))} (P \times R)) – \Pi_x (\sigma_{(Q.Y = R.Y \wedge Q.T>2))} (Q \times R))\)
Answer: ___________.
Attempted by 113 students.
Show answer & explanation
Correct answer: 1
Answer: 1 tuple — X2
First part: select R rows with V = V2. These R rows have Y = Y3 and Y = Y2.
Join P with those R rows on Y (P.Y = R.Y). Only the P row with Y = Y2 (X2, Y2, Z2) matches, so projecting X gives X2.
Second part: keep Q rows with T > 2. These are the rows (X1, Y2, 5) and (X1, Y1, 6).
Join those Q rows with R on Y. The row with Y2 matches two R rows (giving X1) and the row with Y1 matches one R row (also giving X1). Projecting X yields X1.
Take the set difference: {X2} minus {X1} = {X2}. So the query returns a single tuple with X = X2.
A video solution is available for this question — log in and enroll to watch it.