ITPub博客

首页 > 数据库 > Oracle > SQL中的左连接和右连接

SQL中的左连接和右连接

原创 Oracle 作者:charsi 时间:2012-01-06 18:07:24 0 删除 编辑

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博客 ” ,链接:https://blog.itpub.net/23850820/viewspace-1057056/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: java 6 64位
请登录后发表评论 登录
全部评论

注册时间:2010-05-04

  • 博文量
    96
  • 访问量
    406716