Reputation: 868
I need to give condition inside mysql query ,
select IF(r.name=NULL,'customer',r.name) as previlage
from users u LEFT JOIN role r on r.rid = u.uid ORDER BY u.created DESC\G
i need to check if the r.name field is null then it should be displayed as
customer
,but now if r.name is NULL then its displayed as null itself
. How can i achieve this .Thank you .
Upvotes: 1
Views: 113
Reputation: 44874
You can not compare NULL
with =
, you need to use is null
r.name is null
instead of
r.name=NULL
https://dev.mysql.com/doc/refman/5.0/en/working-with-null.html
Upvotes: 3