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 operator in the WHERE Clause to apply multiple filters on the rows returned by SELECT Statement. This operator returns the result as:
- 1, if all operands are non nulls, and if an odd number of operands are non zeros, otherwise 0.
- NULL, If either of the operands are NULL.
In this article we will show you, How to use the MySQL Logical Operator XOR in the WHERE Clause to filter the data. In order to explain the XOR operator, we are going to use the below shown data.
MySQL XOR Operator – Command prompt
In this example we will pass Ones, Zeros, and Null values with different combination. This example helps you to understand the Truth table behind the 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;
MySQL XOR Operator Example
In MySQL, XOR Operator is used to test multiple conditions in WHERE Clause. If either one of the conditions is TRUE then it will display 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;
Thank You for Visiting Our Blog