SQL的WHERE子句中包含多個AND和OR,那么這些條件有什么優先順序嗎?
例如:
SQL解析器在處理操作時會優先處理and操作:
假如有表product字段如下:id、product_id、product_price、product_name,現在要查找產品號為100或者101,并且價格大于200的商品,程序員可能會這樣寫:
select * from product where product_id = 100 or product_id = 101 and product_price > 200
上述代碼中,SQL解析器首先進行and 的操作,最后就成了這個意思:查找產品號為101且價格大于200或產品號為100 的商品。
添加圓括號即可:
select * from product where (product_id = 100 or product_id = 101) and product_price > 200
sql注入中的萬能密碼一般都會多加幾個or,username' or 1=1 or 1=1 --+
以上就是sql語句中條件語句where后的多個and/or的優先級的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持錯新網。新聞熱點
疑難解答