inner join和left join和outer join


1、有兩個表數據

a、表accu

create table accu
(
    day_code varchar2(10),
    buss_month varchar2(10),
    fnum int
)
insert into accu values('20210927','202109',1);
insert into accu values('20210928','202110',2);
insert into accu values('20210927','202109',2);
insert into accu values('20210929','202110',3);
insert into accu values('20210930','202110',4);
insert into accu values('20211001','202110',5);

b、表sell

create table sell
(
  day_code varchar2(10),
  sname varchar2(50),
  fruit varchar2(50)  
)
insert into sell values('20210927','張三','蘋果');
insert into sell values('20210927','李四','西瓜');
insert into sell values('20210930','王五','');
insert into sell values('20211027','張三','李子');

 

2、inner join(相當於join)

select accu.*,sell.* from ACCU inner join sell on accu.day_code=sell.day_code;
--返回兩個表中關聯字段相等的行
--等價於select accu.*,sell.* from accu,sell where accu.day_code=sell.day_code;

 

 

 3、left join

select accu.*,sell.* from ACCU left join sell on accu.day_code=sell.day_code;
--返回字段關聯相等時左邊表和右邊表組成的行,還有字段關聯不相等時左邊關聯不成功的行,右邊表字段為空組成的行
--等價於select accu.*,sell.* from accu,sell where accu.day_code=sell.day_code(+);

 

 4、outer join

outer joio 可分為left outer join、right outer join和full outer join。

left outer join和left join是一樣的,right outer join和right join是一樣的。

select accu.*,sell.* from accu full outer join sell on accu.day_code=sell.day_code;
--字段關聯相等時左邊表和右邊表字段組成的行,字段關聯不相等時左邊表字段和右邊表字段設為空的行,還有右邊表字段和左邊表字段設為空的行

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM