tags:

views:

25

answers:

3

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.

+2  A: 

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-statement.html

Chris Diver
+4  A: 

SELECT CASE WHEN bool_value <> 0 THEN "yes" ELSE "no" END

Will A
+1  A: 

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

mdma
+1 Thanks, also useful information.
alex