How to compute a natural join?

若如初见. 提交于 2019-12-12 09:58:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!