简体   繁体   中英

can we replace full join with union of left and right join? why not?

can we replace full join with union of left and right join? if no,why?

'YES' if T1 and T2 are sets (no duplicated rows), otherwise the answer is 'NO'.

create table t1 (i int);
create table t2 (i int);

insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (2);

insert into t2 values (3);

FULL JOIN

select * from t1 full join t2 on t1.i=t2.i 
order by 1,2

1   (null)
2   2
2   2
(null)  3

UNION

select * from t1 left join  t2 on t1.i=t2.i
union
select * from t1 right join t2 on t1.i=t2.i
order by 1,2

1   (null)
2   2
(null)  3  

UNION ALL

select * from t1 left join  t2 on t1.i=t2.i
union all
select * from t1 right join t2 on t1.i=t2.i
order by 1,2

1   (null)
2   2
2   2
2   2
2   2
(null)  3

The above explanation really helps. Just one add on the outputs are valid only if we have below value inserted in t2 "insert into t2 values (2);"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM