mysql union all 中使用 含order by子查询 注意事项
union all中使用order by子查询时需将含order by的子查询包在一个不含order by的查询里再进行union all。否则会报“Incorrect usage of UNION and ORDER BY”例如:1.错误用法: select id from test1 order by id union all
·
union all中使用order by子查询时需将含order by的子查询包在一个不含order by的查询里再进行union all。
否则会报“Incorrect usage of UNION and ORDER BY”
例如:
1.错误用法:
select id from test1 order by id
union all
select id from test2 order by id
2.正确用法:
select * from (select id from test1 order by id) t1
union all
select * from (select id from test2 order by id) t2
更多推荐
已为社区贡献4条内容
所有评论(0)