Natural Join of two relations with more than 1 common attribute?

1.9k views Asked by At

My actual task: Are the following two relations equivalent, why, why not?/)

r5: PROJECT B (R) JOIN PROJECT B (U)
r6: PROJECT B (R JOIN U)

img http://s29.postimg.org/hgfgfmptx/zzz.png

while R(ABC) and U (AB)

I've concluded that r5 will generate a relation with a single attribute B containing the common values for B which R and U share.

However I get stuck at r6. Which values of B will r6 generate? being that these two relations share 2 attributes.

Thanks a lot!

1

There are 1 answers

0
AntC On BEST ANSWER

(Natural) JOIN matches on all attributes in common (same attribute name).

In r5, B is projected on R and on U before joining. So the only attribute in common is B. (And the values in attributes A and C get ignored.)

r5 is equivalent to

    SELECT B
      FROM R, U
     WHERE R.B = U.B

In r6, the attributes in common for (R JOIN U) are B and A. So the result of that join has only the tuples from R and U which have the same value for both A and B.

r6 is equivalent to:

    SELECT B
      FROM R, U
     WHERE R.B = U.B AND R.A = U.A