Are the two statements below equivalent?
SELECT [...]
FROM [...]
WHERE some_col in (1,2,3,4,5) AND some_other_expr
and
SELECT [...]
FROM [...]
WHERE some_col in (1,2,3) or some_col in (4,5) AND some_other_expr
Is there some sort of truth table I could use to verify this?
I'll add 2 points:
So, the 2 expressions are simply not equal.
So, when you break the IN clause up, you split the serial ORs up, and changed precedence.
And
has precedence overOr
, so, even ifa <=> a1 Or a2
is not the same as
because that would be Executed as
and what you want, to make them the same, is
Here's an example to illustrate:
For those who like to consult references (in alphabetic order):
You can use parentheses to override rules of precedence.
Query to show a 3-variable boolean expression truth table :
Results for
(A=1) OR (B=1) AND (C=1)
:Results for
(A=1) OR ( (B=1) AND (C=1) )
are the same.Results for
( (A=1) OR (B=1) ) AND (C=1)
: