有以下数据
table1
字段:A, B, C, D
001, 1, 1,
002, 1, 1, A
table2
字段:A, B, C, D
001, 1, 1, D
结果要显示为:
字段:A, B, C, D
001, 1, 1,
002, 1, 1, A
001, 1, 1, D
我的sql是
select a,b,c,d
from (select table1.a a, table1.b b, table1.c c, table1.d d
from table1
union
select table2.a a,table2.b b, table2.c c, table2.d d
from table2
)
order by d,a
table1
字段:A, B, C, D
001, 1, 1,
002, 1, 1, A
table2
字段:A, B, C, D
001, 1, 1, D
结果要显示为:
字段:A, B, C, D
001, 1, 1,
002, 1, 1, A
001, 1, 1, D
我的sql是
select a,b,c,d
from (select table1.a a, table1.b b, table1.c c, table1.d d
from table1
union
select table2.a a,table2.b b, table2.c c, table2.d d
from table2
)
order by d,a
from table1
union
select *
from table2
order by d,a
select table1.a a, table1.b b, table1.c c, table1.d d
from table1
union
select table2.a a,table2.b b, table2.c c, table2.d d
from table2 不需要order by也是这结果,你的顺序根本就没变