0

Given a query ending in where a and b and c or d, will this behave as where (a and b and c) or d, or where a and b and (c or d)? (Or something else?)

I've read the docs and they seem to suggest it would be the former as and has a higher precedence than or, but my results seem to performing the latter so I'm wondering if I'm either misunderstanding the docs or else I'm not generating the query correctly (via an ORM).

cb7
  • 135
  • 1
  • 3

1 Answers1

2

If the query purpose is unclear, then you should make it clear.

You don't want to be relying on some relatively obscure ordering rules to get it right. You can't rely on them always staying the same throughout different versions of the same product, or if the underlying technology changes (e.g. Oracle -> MySQL).

If you want it to behave in one way, make it explicit how you want it to behave by using parentheses.

Rick James
  • 80,479
  • 5
  • 52
  • 119
Phil Sumner
  • 1,906
  • 11
  • 13