Consider the relations R(A, B) and S(B, C) and the following four relational algebra queries over R and S:
Show answerHide answer
Correct answer: (D) I, II and III are the same query
Explanation
I, II and III all return exactly those tuples of R whose B value appears in S, whereas IV returns every (A, R.B) pair of R as long as S is non-empty. Example: R = {(10, 1), (20, 2)}, S = {(2, 30), (3, 40)}. (I) R ⋈ S = {(20, 2, 30)}, so π_A,B(R ⋈ S) = {(20, 2)}. (II) π_B(S) = {(2), (3)}, so R ⋈ π_B(S) = {(20, 2)}. (III) π_A(R) × π_B(S) = {(10, 2), (10, 3), (20, 2), (20, 3)}, and R ∩ that = {(20, 2)}. (IV) π_A,R.B(R × S) = {(10, 1), (20, 2)}. So I, II and III are the same query.