一,有嵌套查询,并且子查询中用了union all合并两个查询时,前一个查询用了order by,那么会报错并提示ORA-00907:missing right parenthesis缺少右括号:
select * from (
select t.* from emp t where t.job='MANAGER' order by t.empno
union all
select t.* from emp t where t.job='SALESMAN'
)
不要像上面那样写,如果要实现排序的功能,可以这样写:在union all语句的最后面使用order by+数字(数字表示排序的字段的索引)
select t.* from emp t where t.job='MANAGER'
union all
select t.* from emp t where t.job='SALESMAN' order by 1
二,使用in的子查询中用了order by
select t.* from emp t where t.empno in(select t.empno from emp t order by t.empno )
正确的写法是子查询中去掉order by