I have a table as below
Table foobar
|foo|bar|
---------
| 1 | 1 |
| 1 | 0 |
| 0 | 1 |
| 0 | 0 |
I need to be able to do something similar to this
select * from foobar
where foo = 1 or bar = 1
Which would return the below
|foo|bar|
---------
| 1 | 0 |
| 0 | 1 |
Meaning that what is returned is exclusively 1 for the value. Is there such a thing as XOR in mysql that functions like this?
Yes, XOR. MySQL XOR operator checks two operands (or expressions) and returns TRUE if one or the other but not both is TRUE.
select * from foobar
where foo = 1 XOR bar = 1
The actual mathematical representation of a XOR equation "A XOR B
" is "(A AND (NOT B)) OR ((NOT A) AND B)
".
try like this:
select * from test where foo = 1 XOR bar = 1;
Sql Fiddle: http://sqlfiddle.com/#!2/079cc/4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With