Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL order of operations for logical operands

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.

like image 923
user3654225 Avatar asked Dec 29 '25 23:12

user3654225


1 Answers

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

A OR (B AND C AND D) OR E
like image 133
The Impaler Avatar answered Jan 01 '26 12:01

The Impaler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!