J-H
J-H

Reputation: 1869

Return "true" if two columns in record are equal?

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

Answers (1)

juergen d
juergen d

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

Related Questions