Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: return "0" & "1" rather than "false" & "true"

Tags:

sql

I need to return true or false rather than 1 & 0, using following query:

select if(u.id is null,false,true) status
from user u
limit 10

the above query returns status with value 0 or 1 rather than true and false,

Is there any way to fix this?

like image 604
mwafi Avatar asked Dec 08 '22 23:12

mwafi


2 Answers

If you want, you can return the values as strings:

SELECT IF(u.id IS NULL, 'false', 'true') as status
FROM user u
LIMIT 10
like image 61
Gordon Linoff Avatar answered Dec 14 '22 23:12

Gordon Linoff


TRUE/FALSE is equivalent to 1/0. It's just a matter of how your front end displays it.

If you need to return the strings "true" and "false" (which I don't suggest - handle that in the display) then you'll have to account for that as well:

IF(IF(u.id ISNULL,false,true) = 1, 'TRUE', 'FALSE')

like image 23
Tom H Avatar answered Dec 14 '22 23:12

Tom H