Mysql XOR

Mysql XOR returns you the output on the basis of condition specified in input. The output of the XOR is 0 when both the specified inputs are same.

Mysql XOR

Mysql XOR

     

Mysql XOR returns you the output on the basis of condition specified in input. The output of the XOR is 0 when both the specified inputs are same. The output is 1 when two input are different. To understand the Mysql XOR logical operation we provide you a demonstrative example below:

Query to use xor operation Truth Table

  A   B   Output
  0  0  0
  0  1  1
  1  0  1
  1  1  0

 

Query when the both input is '0' output is ' 0':

The below query is useful when you want the return output is 0. In this case we use 0and 0 as input and return you 0 as output.

mysql> SELECT 0 xor 0;
+---------+
| 0 xor 0 |
+---------+
| 0 |
+---------+
1 row in set (0.00 sec)

 Query one input is '0' and other is '1' then output is '1':

The below Query XOR return you '1' when 0 xor 1 or  0 xor1 (different types of input ).

mysql> SELECT 0 xor 1;
+---------+
| 0 xor 1 |
+---------+
| 1 |
+---------+
1 row in set (0.00 sec)

 

mysql> SELECT 1 xor 0;
+---------+
| 1 xor 0 |
+---------+
| 1 |
+---------+
1 row in set (0.00 sec)


Query both input is '1' then output is '0':

The Query return the output 0 when both the inputs are 1 or 0.

mysql> SELECT 1 xor 1;
+---------+
| 1 xor 1 |
+---------+
| 0 |
+---------+
1 row in set (0.00 sec)