当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