我需要在mysql查询中给出条件,
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
我需要检查if the r.name field is null then it should be displayed as
customer
,但现在if r.name is NULL then its displayed as null itself
。我怎样才能做到这一点。谢谢。
答案 0 :(得分:3)
您无法将NULL
与=
进行比较,您需要使用is null
r.name is null
而不是
r.name=NULL
https://dev.mysql.com/doc/refman/5.0/en/working-with-null.html