I have a BOOLEAN type column in my table. I would like to convert the 0/1 to Yes/No when the results are returned.
I found a response on this thread: Echo boolean field as yes/no or other values
The response mentioned an IF THEN statement, but when I try, I only get a complaint from MySQL that there is a syntax error. Here is the line I am using:
IF qz.quiz_enabled == 1 THEN 'yes' ELSE 'no' AS enabled
Here is the error:
use near 'qz.quiz_enabled == 1 THEN 'yes' ELSE 'no' AS enabled
MySQL doesn't really have booleans. TRUE and FALSE are aliases to 1 and 0, and the BOOL column type is just an alias for TINYINT(1) . All expressions that appear to give boolean results actually return 0 or 1.
You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
MySQL defines a value of 0 as false and a non-zero value as true. Therefore, to use Boolean literal values, you use the constants TRUE and FALSE that evaluate the value of 0 and 1. From the above, we can deduce that MySQL considers 1 and 0 as True and False, respectively.
MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.
select case when qz.quiz_enabled
then 'yes'
else 'no'
end
or
select if(qz.quiz_enabled, 'yes', 'no')
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