Operation Order for SQL?

Suppose I have this statement:

SELECT * FROM MyTable WHERE a = 1 or b = 2 and c = 3 

Does this mean: (a = 1) OR (b = 2 AND c = 3) or does it mean (a = 1 or b = 2) And c = 3? Can I change what this means, i.e. Run OR before AND or is it impossible?

+4
source share
1 answer

From Technet :

When a statement uses more than one logical operator, AND first evaluates the operators. You can change the order of evaluation using parentheses.

So this means (a = 1) OR (b = 2 AND c = 3) .

You can force the behavior you want by writing the brackets as you did above: (a = 1 OR b = 2) AND c = 3

+10
source

All Articles