MySQL XOR Operator is one of the Logical Operators. In mathematics, x XOR y is equal to (x AND (NOT y)) OR ((NOT x) AND y). Generally, we use this MySQL XOR operator in the WHERE Clause to apply multiple filters on the rows or records returned by the SELECT Statement. This XOR operator returns the result as:
- 1, if all operands are no nulls, and if an odd number of operands are non-zero, otherwise 0.
- NULL, If either of the operands is NULL.
To explain the Logical XOR Operator in the WHERE Clause, we are going to use the below shown data.
MySQL XOR Operator Command prompt
In this MySQL example, we pass Ones, Zeros, and Null values with a different combinations. This example helps you to understand the Truth table behind this XOR Operator.
SELECT 1 XOR 1; SELECT 1 XOR 0; SELECT 0 XOR 0; SELECT 1 XOR NULL; SELECT 1 XOR 1 XOR 1 XOR 0; SELECT 0 XOR NULL;
Logical XOR Operator Example
USE company; SELECT CustID, First_Name, Last_Name, Education, Profession, Yearly_Income, Sales FROM customers WHERE Education = 'High School' XOR Yearly_Income > 90000;