如果条件里面有mysql查询

时间:2015-10-20 08:40:15

标签: mysql if-statement

我需要在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。我怎样才能做到这一点。谢谢。

1 个答案:

答案 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

相关问题