Can I Join 3 table using Natural Join?

孤者浪人 提交于 2019-12-13 00:53:02

问题


The image down below shows a small database,

I got a question

Give a relational algebra expression to find the name of the judge who presides over the trial for defendant known as “Mike” starting on 1.12.2012.

And the answer given is


But I think it should Join JUDGE table as well something like this :

Please leave some comment if I' wrong about this


回答1:


Nope, you don't need to join the JUDGE table to get the judge's name.

Notice how Jname is the primary key of JUDGEs, that is to say, a judge is uniquely identified by her name; and the TRIAL table will actually contain Jname denoting which judge presided over a given trial:

Judge | Defendant | Number | Sdate
Dredd |  1        |   1    | 1.12.2012
Dredd |  2        |   2    | 2.12.2012
Rico  |  1        |   3    | 1.12.2012

You can see how selecting tuples yields us the judge's name without joining anything in. (In case you're wondering, this is a very bad design that you should never employ in the real world.)

In contrast, we do have to join DEFENDANT with TRIAL: a DEFENDANT's primary key is his ID, so only that ID appears in the TRIAL table, so if we need to select a defendant by name, we have to employ a join.

As for your question title: yes, you can of course join more than three tables. If you find it hard to imagine, recall that R ⨝ S ⨝ T = (R ⨝ S) ⨝ T. Note that natural join is nicely commutative and associative as well.



来源:https://stackoverflow.com/questions/19740069/can-i-join-3-table-using-natural-join

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