左关联右关联全关联

左关联右关联全关联
参考:http://www.cnblogs.com/lovemoon714/archive/2012/03/02/2376782.html

select * from trans_batch;
select * from trans_detail;
--select * from trans_batch;
--select * from trans_detail;
select count(*) from (
select * from trans_batch b,trans_detail e where b.id=e.trans_batch_id);
--内连接
select count(*) from (
select * from trans_detail d inner join trans_batch b on b.id=d.trans_batch_id) ;
select count(*) from (
select * from trans_detail d join trans_batch b on b.id=d.trans_batch_id) ;
--左连接 :列出左边表全部的,及右边表符合条件的,不符合条件的以空值代替。
select count(*) from (
select b.* from trans_detail d left join trans_batch b on b.id=d.trans_batch_id) ;

--右连接 列出右边的全部值,这边是符合条件关联值,没有的用空值代替
select count(*) from (
select d.* from trans_detail d right join trans_batch b on b.id=d.trans_batch_id) ;

--在(+)计算时,哪个带(+)哪个需要条件符合的,另一个全部的。即放左即右连接,放右即左连接。
----左连接
select count(*) from (
select d.* from trans_detail d, trans_batch b where d.trans_batch_id=b.id(+) );

select count(*) from (
select d.* from trans_detail d, trans_batch b where d.trans_batch_id(+)=b.id );

--全连接
----全连接 :产生M+N的结果集,列出两表全部的,不符合条件的,以空值代替。
select count(*) from (
select b.* from trans_detail d full join trans_batch b on b.id=d.trans_batch_id) ;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值