一,有嵌套查詢,并且子查詢中用了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
?