The priority of the AND and OR operator in a Mysql select query

I have a mysql select query to retrieve schedule information based on baseline, city of origin, country of destination and city of destination. In my query, I used the AND and OR operator.

Here is my request

 SELECT * FROM TruckLoadSchedule ts WHERE ts.originState IN (states) AND ts.originCity IN (cities) OR ts.destState IN (states) AND ts.destCity IN (cities); 

But I need to know the priority of the AND and OR operator in the above query, I want to say that it will do something like this (X AND Y) OR (M AND Q) internally?

+8
mysql operator-precedence
source share
3 answers

Yes, And has a higher priority than OR. x and y are connected together, m and q are connected together, then the resulting ORed expressions.

+8
source share

And it has a higher priority than OR in every programming language that I have ever seen, and I saw several dozen in the immediate environment and myself implemented several. This issue was mainly resolved in 1960 with the report of Algol-60, if it had not yet been in Fortran (1957).

[There was one exception, but it was a mis-implemented language without any operator precedence. I fixed it.]

+1
source share

Yes, he will do something like (X AND Y) OR (M AND Q) . AND operator precedence above OR .

See MySQL for more details : Operator Priority

+1
source share

All Articles