select 'A', '', '' from dual
union
select 'B', '', '' from dual;
结果是这样:
A NULL NULL
B NULL NULL
select p1.t1, p2.t2, p2.t3 from
(select 'A' as t1,'' as t2,'' as t3 from dual ) p1 join
(select '' as t1, '' as t2, '' as t3 from dual where 1=2) p2 on p1.t1 = p2.t1
union all
select p1.t1, p2.t2, p2.t3 from
(select 'B' as t1,'' as t2,'' as t3 from dual ) p1 join
(select '' as t1, '' as t2, '' as t3 from dual where 1=2) p2 on p1.t1 = p2.t1
希望的结果和上面的sql的结果是一样的,但是,查询出来确实空。
测试数据库是oracle。
如果把union all 换成union, 结果变成期望的效果。
WHY?