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的优先级的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持武林网。新闻热点
疑难解答