Reputation: 1869
I'm looking for an possibility to check in an sql statement if various columns equal each other and return true or false:
For Example: 4 Columns (a,b,c,d) and I want to check if a LIKE b and c LIKE d and if true then return true(or 1)...
Is this possible to do this in mysql? i'm actually solving this with php in 2 steps but this sucks..
thx for your advice
Upvotes: 2
Views: 7922
Reputation: 204854
In MySQL
select a = b AND c = d as is_check_true
from your_table
will return 1
if true and 0
otherwise.
To make this work with other DB engines you can use
select case when a = b AND c = d
then 1
else 0
end as is_check_true
from your_table
Upvotes: 12