简体   繁体   中英

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.

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

A OR (B AND C AND D) OR E

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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