How to compute a natural join?

試著忘記壹切 提交于 2019-12-06 14:29:43

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)}

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

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