XOR is a logical operator that implements exclusive OR semantics. It evaluates two Boolean expressions and returns 1 (true) if either expression is true but not both; otherwise it returns 0 (false). XOR is not part of the ANSI SQL standard, but MySQL and MariaDB include it as both a logical and bitwise operator. When used in a Boolean context, non-zero numeric values are treated as true and zero as false. When either operand is NULL, the result is NULL, mirroring three-valued logic behavior. Databases that lack a native XOR operator can emulate it with expressions such as `(a AND NOT b) OR (NOT a AND b)` or with `a <> b` for Boolean inputs. XOR is evaluated after OR but before the assignment operator in MySQL’s operator precedence table. Because of its limited dialect support, portable code should prefer an emulation expression instead of the native keyword.
expression1
(Boolean or numeric) - First value to compareexpression2
(Boolean or numeric) - Second value to compareMySQL 3.x
Only MySQL and MariaDB implement XOR natively. Other systems require an emulation expression.
Use `(expr1 AND NOT expr2) OR (NOT expr1 AND expr2)` or, for Boolean columns, `expr1 <> expr2`.
No. MySQL treats XOR as a logical operator on Boolean values, while `^` is a bitwise XOR on integer bits.
XOR has lower precedence than AND but higher precedence than assignment operators. Use parentheses to guarantee evaluation order when mixing operators.