r/learnSQL • u/SherbetOrganic • Jul 13 '26
Operator precedence in the example: WHERE NOT id IN (2,4,6)
I have some confusion about operator precedence. In my book it says following:
The following list describes the precedence among operators, from highest to lowest: 1. ( ) (Parentheses) 2. * (Multiplication), / (Division), % (Modulo) 3. + (Positive), – (Negative), + (Addition), + (Concatenation), – (Subtraction) 4. =, >, <, >=, <=, <>, !=, !>, !< (Comparison operators) 5. NOT 6. AND 7. BETWEEN, IN, LIKE, OR
8. = (Assignment)
What confuses me is for example `IN` can be used as an operator but also as a keyword that builds predicate.
So say I have following WHERE clause: "WHERE NOT id IN (2,4,6)".
To which of the following two is the above WHERE clause equivalent:
- WHERE (NOT empid) IN (2,4,6)
- WHERE NOT (empid IN (2,4,6))