Timur Ridjanovic
Timur Ridjanovic

Reputation: 1012

Compute theta join in relational algebra

I`m having trouble with this problem:

Suppose relation R(A,B) has the following tuples:

A   B
1   2
3   4
5   6

and relation S(B,C,D) has the following tuples:

B   C   D
2   4   6
4   6   8
4   7   9

Compute the theta-join of R and S with the condition R.A < S.C AND R.B < S.D. Which of the following tuples is in the result? Assume each tuple has schema (A, R.B, S.B, C, D).

Choose from the following answers:

(3,4,2,4,6)
(1,2,4,4,6)
(1,2,2,6,8)
(3,4,4,7,8)

So when I try it, I see that

(1, 2) matches (2, 4, 6)
(3, 4) matches (4, 6, 8)
(3, 4) matches (4, 7, 9)

so I found the following tuples (they all respect the condition):

(1, 2, 2, 4, 6)
(3, 4, 4, 6, 8)
(3, 4, 4, 7, 9)

The problem is that none of these are found in the multiple choices...

Am I doing something wrong?

Thanks for the help!

Upvotes: 1

Views: 4268

Answers (1)

Sruti
Sruti

Reputation: 670

To compute a theta-join, one basically does a cartesian product of the two relations, (here, R and S), and arrives at all possible combinations. On each of these tuples, you apply the condition theta and get the ones that are true.

Here, the cartesian gives 3x3 = 9 tuples. Of them, 8 tuples satisfy the condition (R.A < S.C AND R.B < S.D). That makes the tuple (3,4,2,4,6) an element of the theta join set.

What you have done is an a theta join for (R.B = S.B AND R.A < S.C AND R.B < S.D). Hope that helps you get the difference.

Upvotes: 3

Related Questions