打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
sql之join用法完全版【转载】

 SQL中大概有这么几种JOIN

cross join

inner join

left outer join  

right outer join 

full outer join

 

首先都是基于cross join(笛卡尔乘积),然后是inner join,在笛卡尔乘积的结果集中去掉不符合连接条件的行。

left outer join 是在inner join的结果集上加上左表中没被选上的行,行的右表部分每个字段都用NUll填充。

right outer join 是在inner join的结果集上加上右表中没被选上的行,行的左表部分全用NULL填充。


SQL JOIN 用法完全版

一、各种JOIN的含义

SQL中大概有这么几种JOIN

cross join

inner join

left outer join  

right outer join 

full outer join

 

首先都是基于cross join(笛卡尔乘积),然后是inner join,在笛卡尔乘积的结果集中去掉不符合连接条件的行。

left outer join 是在inner join的结果集上加上左表中没被选上的行,行的右表部分每个字段都用NUll填充。

right outer join 是在inner join的结果集上加上右表中没被选上的行,行的左表部分全用NULL填充。

outer的意思就是"没有关联上的行"。

 

二、旧式写法和标准写法:

 

1INNER Join code as the following:

 

Select * from A a, B b where a.categoryID = b.categoryID;

Equals:

Select * from A a inner join B b on a.categoryID = b.categoryID;

 

2OUTER Join code as the following

 

select * from A a full(left/right) outer  join B b  on a on a.categoryID = b.categoryID;

Equals::

Select * from A a, B b where a.categoryID *=  b.categoryID;

Select * from A a, B b where a.categoryID =*  b.categoryID;

 

三、例子

Table A have 12( 8+4) entries, 8 entries have valid relation with B

Table B have 80(77+3) entries , 77 entries have valid relation with A.

 

then the return amount of join is :

cross join : 12*80

inner join : 77

full outer join : 77+4+3

left outer join: 77 + 4

right outrer join: 77 + 3

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
多表查询(各种连接)
inner join on, left join on, right join on讲解
sql语法:inner join on, left join on, right join on详细使用方法
SQL的各种连接(cross join、inner join、full join)的用法理解
left join 和 left outer join 的区别
SQL-- JOIN之完全用法(版本2)【转】
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服