SQL中的左连接和右连接的概念其实相同,只是为了在语言上区分而已。即如果把左边的放在右边,或者右边的放到左边,那么左连接也就变成右连接了.
左连接其实就是连接左边表中的数据和右边的数据关联。包括所有左边表的数据和符合关联条件的数据。
如下所示:
SQL>
SQL> create table a (x number);
Table created.
SQL> create table b (y number);
Table created.
SQL> insert into a values (1);
1 row created.
SQL> insert into a values (2);
1 row created.
SQL> insert into a values(3);
1 row created.
SQL> insert into b values(3);
1 row created.
SQL> insert into b values(4);
1 row created.
SQL> insert into b values(5);
1 row created.
SQL>
SQL>
SQL> commit;
Commit complete.
SQL>
SQL>
SQL> select * from a,b where a.x=b.y;
X Y
---------- ----------
3 3
SQL> select * from a,b where a.x=b.y(+); --右连接
X Y
---------- ----------
1
2
3 3
SQL>
SQL>
SQL> select * from a,b where a.x(+)=b.y; --左连接
X Y
---------- ----------
3 3
4
5
SQL>
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23850820/viewspace-1057056/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23850820/viewspace-1057056/