昨天工作過程中發現一個奇怪的地方:
代碼段A:
1---select * from table1
2---order by no
3---union all
4---select * from table2
運行代碼段1,在第三步顯示命令未正確結束。我自然很困惑,問了前輩才知道原來問題出在order by上。
修改后的代碼段A1:
1---select * from table1
2---union all
3---select * from table2
4---order by no
修改后的代碼A1可正常運行。
我在網絡上找了很多說法:
說法1:order by的優先級低於union all,代碼段A中會先運行union all,再運行order by。(但是這個為什么會對運行有影響呢?)
說法2:order by是在本地運行的。(這個也沒想明白影響的原因。)
決定再問一下前輩。
看來對於數據庫我還有很多不知道的地方。要多多學習,多多進步。
