當union all和order by 如下一起使用時,會報sql未正確結束
select name,age from student order by age
union all
select name,age from person order by age
通用的解決方法有三種:
1、將結果集作爲一張臨時表然後查詢排序
select * from (select name,age from student order by age
union all
select name,age from person order by age) order by age
2、單獨對錶進行排序後進行並集操作
select * from (select name,age from student order by age)
union all
select * from (select name,age from person order by age)
3、order by + 字段在結果集中的序號
select name,age from student
union all
select name,age from person
order by 2