MySQL XOR Operator is one of the Logical Operator. 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 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 MySQL 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.
-- MySQL XOR Operator Example 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;
OUTPUT
Logical XOR Operator Example
The XOR Operator test multiple conditions in WHERE Clause. If either one of the conditions in the WHERE Clause is TRUE, then the SELECT Statement displays the records.
-- MySQL 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;
OUTPUT