Reputation: 490403
If I have a column set up as Boolean in MySql, a query returns the value as either 0
or 1
.
Is it possible to do something like this
SELECT `bool_value` AS "yes" OR "no"
What I mean is, return two different strings based on whether it is true or false.
Upvotes: 23
Views: 25671
Reputation: 19842
You need the case
statement.
SELECT (CASE WHEN column <> 0 THEN 'yes' ELSE 'no' END) As Value
http://dev.mysql.com/doc/refman/5.0/en/case.html
Upvotes: 32
Reputation: 57747
MySql supports the standdard SQL CASE statement, which other answers use. MySQL also has the shorter, but non-standard IF statement
SELECT IF(bool_value,'Yes','No')
See
Upvotes: 33