在sql语句中条件语句where后的多个and/or的优先级
发布时间:2023-10-24 14:30:13 所属栏目:经验 来源:
导读:SQL的WHERE子句中包含多个AND和OR,那么这些条件有什么优先顺序吗?
例如:
SQL解析器在处理操作时会优先处理and操作:
假如有表product字段如下:id、product_id、product_price、product_name
例如:
SQL解析器在处理操作时会优先处理and操作:
假如有表product字段如下:id、product_id、product_price、product_name
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 --+ (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐