Translating existential joins into relational algebra
Relational Algebra & Calculus

Answer & solution
Official answer: B
Givens and goal
Relations are R(P,Q) and S(X,Y). The query returns u whenever there exist v,w with (u,v) in R and (v,w) in S. Select the equivalent projection/join expression. The alternatives join P to X, Q to X, P to Y, or Q to Y, and all project P.
Approach
Map each quantified variable to its relation attribute, use the repeated variable as the join equality, and project the requested output coordinate.
Step-by-step solution
1. Membership (u,v)∈R means u=R.P and v=R.Q. Membership (v,w)∈S means v=S.X and w=S.Y.
2. The same variable v occurs in both tuples, so qualifying tuple pairs must satisfy R.Q=S.X. This is the equijoin condition; neither R.P nor S.Y is the repeated coordinate.
3. After joining, the query asks only for u. Since u is R.P, project attribute P from the join. Thus the expression is π_P(R ⋈_(R.Q=S.X) S).
4. Option B writes the operands in the reverse order, π_P(S ⋈_(S.X=R.Q) R), which is equivalent for this inner equijoin and projection. Therefore select B.
5. For example, R containing (a,7) and S containing (7,b) must produce a. The two 7 values are the ones that need to match. Joins equating P with X, P with Y, or Q with Y would impose a different condition. The existential variables v and w disappear from the output through projection; ordinary relational algebra uses set semantics here.

