sql查詢條件位置和執行順序

2021-09-02 21:24:30 字數 581 閱讀 4220

經常有這樣的場景:在頁面的**處顯示指標的資料,如果指標的資料不存在,那麼指標的名稱也不會顯示。而實際上,有時候是需要顯示名稱的,因為這樣可以知道頁面區域的內容,沒有資料是另外一回事,因此,我們需要對sql的執行原理有一定認識,才不會走太多的彎路。

如下sql:

select

* from

class c  

left

join

student s 

onc.classid=s.classid 

ands.studentid=

'hhhhll'

是先對 s進行篩選,然後再join

如下sql:

select

* from

class c  

left

join

student s 

onc.classid=s.classid   

where

s.studentid=

'llllffff'

是先join,再篩選資料。

對於第二種情況,如果沒有學生,那麼課程也就顯示不了了,也就無法看到已有的課程。

SQL 條件語句的執行順序

語句1 select from work order list where head corp id 1 and work order state in 1,2 and receiving id is null or receiving id 27 語句2 select from work orde...

SQL 查詢的執行順序

這張圖與 sql 查詢的語義有關,讓你知道乙個查詢會返回什麼,並回答了以下這些問題 但資料庫引擎並不一定嚴格按照這個順序執行 sql 查詢,因為為了更快地執行查詢,它們會做出一些優化,這些問題會在以後的文章中解釋。所以 有很多 sql 實現允許你使用這樣的語法 select concat first...

sql語句中的where條件執行順序

語句1 select from work order list where head corp id 1 and work order state in 1,2 and receiving id is null or receiving id 27 語句2 select from work orde...