Jessica Posted July 12, 2012 Share Posted July 12, 2012 I'm having a brain fart... how do I do: SELECT col FROM table and if col is NULL, I want a 0, otherwise I want a 1. Quote Link to comment https://forums.phpfreaks.com/topic/265566-if-null-0-else-1/ Share on other sites More sharing options...
Barand Posted July 12, 2012 Share Posted July 12, 2012 SELECT IFNULL(col, 0) as col edit: On second thoughts you prob need SELECT IF(col IS NULL, 0,1) as col Quote Link to comment https://forums.phpfreaks.com/topic/265566-if-null-0-else-1/#findComment-1361070 Share on other sites More sharing options...
Jessica Posted July 12, 2012 Author Share Posted July 12, 2012 That gives me the column's value, or a 0, I want either a 1 or 0, like a boolean of if the field has a value or not, not the actual value. What I really need is Y/N. SELECT IFNULL(group_id, 0) FROM group Gave me 1,2,3,4,5,6,7 etc. Edit: thank you - the second was exactly it. I just couldn't remember if there was a shorthand for it, but IF is what I needed. Quote Link to comment https://forums.phpfreaks.com/topic/265566-if-null-0-else-1/#findComment-1361072 Share on other sites More sharing options...
Barand Posted July 12, 2012 Share Posted July 12, 2012 see my edit Quote Link to comment https://forums.phpfreaks.com/topic/265566-if-null-0-else-1/#findComment-1361074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.