Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql boolean 0/1 To Represent true or False [closed]

Tags:

sql

In my database 1 is used to represent true and 0 to represent false. In my column, now i was wondering if anyone can help me write a query that outputs if the value equals to 1 display true if equals to 0 display false?.

like image 741
Alfred Alfizo Mosima Avatar asked Sep 06 '13 10:09

Alfred Alfizo Mosima


2 Answers

Try to use case

select case when col = 1 then 'true'
            when col = 0 then 'false'
       else 'NN'
       end as val  
like image 77
Robert Avatar answered Oct 24 '22 12:10

Robert


select case when your_bool_column = 1 
            then 'true'
            else 'false'
       end as bool_col
from your_table
like image 37
juergen d Avatar answered Oct 24 '22 13:10

juergen d