问题
Could someone explain to me what is going on here and how to solve this problem?
Suppose relation R(A,B) has the tuples:
A B 1 2 3 4 5 6
and the relation S(B,C,D) has tuples:
B C D 2 4 6 4 6 8 4 7 9
Compute the natural join of R and S. Then, identify which of the following tuples is in the
natural join
R |><| S. You may assume each tuple has schema (A,B,C,D).
I don't know what a natural join truly means. Can you explain it to me?
回答1:
A natural join is joining ("sticking together") elements from two relations where there is a match. In this example
- (1, 2) matches (2, 4, 6) so you get (1, 2, 4, 6)
- (3, 4) matches (4, 6, 8) so you get (3, 4, 6, 8)
- (3, 4) matches (4, 7, 9) so you get (3, 4, 7, 9)
So the natural join is {(1, 2, 4, 6), (3, 4, 6, 8), (3, 4, 7, 9)}
回答2:
I assume R(A,B) is the master, S(B,C,D) is the detail and B is the foreign key.
SQL: select * from R, S where R.B = S.B
Then the result is:
A B C D
1 2 4 6
3 4 6 8
3 4 7 9
来源:https://stackoverflow.com/questions/547014/how-to-compute-a-natural-join