Vote Up 0 Vote Down

mysql if condition in select query

I needto use mysql if condition in select query like following :

select if(mycol,'ok','no') from mytable where id =12;


The mycol value is either 0 or 1. But when I use this I am always getting the value 'ok'. .

I needto get the result as 'ok' when mycol value is 1 and 'no' when it is 0.
flag
edited on 9/6/12

Answers


Vote Up 0 Vote Down
select if(mycol,'ok','no') from mytable where id =12;


The mycol value should be one of the following values ;
1
0
true
false

Check if the mycol value has correct datatype and value.
flag | link |

Your Answer

Login before answering

Login with facebook