SQL order of operations for logical operands

742 views Asked by At

I inherited some some bad SQL code (zero documentation and I'm missing the original requirements). In the where clause, it has the following:

A OR B AND C AND D OR E

From my knowledge of logical operands, my assumption is that SQL would compile this as:

A OR (B AND C AND D) OR E

Is that correct?

I have a feeling the intent was

(A OR B) AND C AND (D OR E)

and I will need to speak with those that requested this project in the first place, as I haven't seen the original requirements.

1

There are 1 answers

0
The Impaler On

You are correct. In the absence of parenthesis this should be interpreted as:

A OR (B AND C AND D) OR E