MySQL - Boolean

Interestingly MySQL uses tinyint(1) to store Boolean data, or bit(1) with no nulls if you want to have a true boolean without nulls. If you look at the Reference Manual on numeric types working with boolean values isn't as straight forward as it might be in C for example. This is both an advantage and disadvantage.

Selecting the value and displaying/working with it can be difficult as many tools (including the MySQL command line tool) Don't always display boolean values as you might expect/want. To get round this you can use IF statements or CAST().

SELECT boolVal,
IF(boolVal, 'True', 'False') AS BoolString,
IF(boolVal = TRUE , 'True', 'False') AS BoolString2,
CAST(boolVal AS UNSIGNED) AS BoolUnsigned,
CAST(boolVal AS SIGNED) AS BoolSigned
FROM sample.table
powered by cmsimple.dk - powered by cmsimple-styles.com