0

Does the SQL query

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;

?

pexmar
  • 331
  • 2
  • 12

1 Answers1

0

No. Boolean operators have precedence rules -- in all programming languages that use them and in mathematics before that. "AND" binds more closely than "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 *). OR less tightly (like +).

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786