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

2021-07-23 23:45:09 字數 599 閱讀 1673

語句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_order_list

where head_corp_id = 1

and receiving_id is null or receiving_id = 27 

and work_order_state in (1,2)

在執行sql語句時,資料庫中通過receiving_id is null or receiving_id = 27可獲取3條資料,work_order_state in (1,2)可獲取2條資料,

當我使用語句1獲取到了兩條資料,使用語句2獲取到了三條資料。

理由是:sql解析器採用自下而上的順序解析where子句,通過此原理可以通過將查詢條件範圍小的語句靠近where,來實現優化。

sql語句中where的引號用法

因為 ip 沒有加單引號 請注意,我們在例子中的條件值周圍使用的是單引號。sql 使用單引號來環繞文字值 大部分資料庫系統也接受雙引號 如果是數值,請不要使用引號。這是正確的 select from persons wherefirstname bush 這是錯誤的 select from pers...

SQL語句中where和 on的區別

join過程可以這樣理解 首先兩個表做乙個笛卡爾積,on後面的條件是對這個笛卡爾積做乙個過濾形成一張臨時表,如果沒有where就直接返回結果,如果有where就對上一步的臨時表再進行過濾。下面看實驗 先準備兩張表 先執行inner join 結果沒有區別,前者是先求笛卡爾積然後按照on後面的條件進行...

sql語句中的where 1 1

1 1 永真,1 1 永假 1 1 的用處 用於只取結構不取資料的場合 例如 create table table temp tablespace tbs temp as select from table ori where 1 1 建成乙個與table ori 結構相同的表table temp,...