简体   繁体   English

带和/或的where子句中的SQL执行顺序

[英]SQL execution order in where clause with and/or

Does the SQL query SQL查询

SELECT * FROM table_a where cond1 or cond2 and cond3;

deliver the same result as 提供与以下结果相同的结果

SELECT * FROM table_a where (cond1 or cond2) and cond3;

?

No. Boolean operators have precedence rules -- in all programming languages that use them and in mathematics before that. 不会。布尔运算符具有优先级规则-在所有使用它们的编程语言中以及在此之前的数学中都有。 "AND" binds more closely than "OR". “ AND”比“ OR”绑定更紧密。 This is analogous to arithmetic operators. 这类似于算术运算符。

Just as: 就像:

1 + 2 * 3

is different from: 不同于:

(1 + 2) * 3

Your two versions are different. 您的两个版本不同。 AND binds more tightly (like * ). AND绑定更紧密(如* )。 OR less tightly (like + ). OR不太紧密(如+ )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM