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?
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
you can use a case when expression
select *, case when gender=false then 'Female' else 'Male' end as gender
from tablename
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