左关联右关联全关联

   左关联右关联全关联
  参考: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) ;

猜你喜欢

转载自wujt.iteye.com/blog/2154220