Reputation: 7175
I have a table called accounts
.
There I have a column called gender
where it's data type is Boolean
.
I want to directly get the gender as a string in my select
query
.
How do I achieve this in MySQL?
Upvotes: 3
Views: 910
Reputation: 96
select gender,IF(gender=1,"Male","Female") as gender2 from accounts
Upvotes: 1
Reputation: 3305
MySql supports the standard SQL CASE statement. MySQL also has the shorter, but non-standard IF statement
SELECT IF(gender,'MALE','FEMALE') as gender from accounts
Upvotes: 5
Reputation: 37473
you can use a case when expression
select *, case when gender=false then 'Female' else 'Male' end as gender
from tablename
Upvotes: 4