Home >Database >Mysql Tutorial >union带有order by的sql时,order by需要放到子查询语法才有效

union带有order by的sql时,order by需要放到子查询语法才有效

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 14:57:561258browse

union带有orderby的sql时,orderby需要放到子查询语法才有效 无 --union和order by连用需要放在子查询中,否则会报错--例如:--错误写法:select * from dept1 order by deptnounionselect * from dept2 order by deptno;--ORA-00933 "SQL command not proper

union带有order by的sql时,order by需要放到子查询语法才有效
--union和order by连用需要放在子查询中,否则会报错
--例如:
--错误写法:
select * from dept1 order by deptno
union
select * from dept2 order by deptno;
--ORA-00933 "SQL command not properly ended"
--正确写法:
select * from (select * from dept1 order by deptno)
union
select * from (select * from dept2 order by deptno);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:统计百分比Next article:快速建立Mysql学习环境