select a,
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
这样是可以的select a,
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
order by t1.a
这样是不行的?这是为何呢?
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
这样是可以的select a,
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
order by t1.a
这样是不行的?这是为何呢?
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
order by t1.a,
b,c,d
oracle 排序是要将你查询的列全部列出,计算列可以除外
不能指定t1.a,因为union all合并了a字段,这里面不单单是t1.a,所以指定t1.a会报错。
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a)
Union all (
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+)
order by t1.a)但是打了括号也不行啊?
select a,b,c,d from (
select a,
b,
c,
d
from tbl_x x, tbl_y y
where x.a = y.a
Union all
select a,
b,
b,
d
from tbl_t1 t1, tbl_t2 t2
where t1.a = t2.a(+))
order by a
将Order by 放在最后
select ...
union all
select * from (select ... order by ...)