A natural (inner) join is defined in relational algebra simply as a joining of tuples from one or more relations on one or more attributes. A simple example is (U INNER JOIN V):
Code:
Relation U:
A B
====
1 2
2 2
3 3
Relation V:
B C
====
2 3
3 5
4 5
To take the natural join, note which tuples agree on the B attribute, and join these. From the above you get the relation:
Code:
A B C
=======
1 2 3
2 2 3
3 3 5
Now, as you can see, one tuple was left out from V (4,5). This is called a dangling tuple. The difference between an inner and an outer join is that in an outer join, dangling tuples are not removed from the resulting relation, thus an outer join using the above sample data would produce:
Code:
A B C
=======
1 2 3
2 2 3
3 3 5
- 4 5
Where '-' is the NULL value. There are two much used versions of outer joins -- the left and the right outer join. In the left outer join, only tuples from the left relation is kept. In the right outer join, only tuples from the right relation are kept. In the above example, a left outer join would result in the same relation as the natural join, whereas a right outer join would produce the same as the natural outer join.
Bookmarks