MySQL选择哪个列不是空的
在MySQL中,我可以只在存在某些东西的情况下选择列吗?
例如,我有以下查询:
select phone, phone2
from jewishyellow.users
where phone like '813%'
and phone2
我试图只选择手机以813开头的行,而phone2有内容。
  将phone2值与空字符串进行比较: 
select phone, phone2 
from jewishyellow.users 
where phone like '813%' and phone2<>''
  请注意, NULL值被解释为false 。 
  要检查字段是否为NULL,请使用IS NULL , IS NOT NULL运算符。 
MySql参考http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html
  检查NULL和空字符串值: 
select phone
, phone2 
from users 
where phone like '813%' 
and trim(coalesce(phone2, '')) <>''
NB我认为COALESCE()是SQL标准(-ish),而ISNULL()不是。
链接地址: http://www.djcxy.com/p/94241.html上一篇: MySQL select where column is not empty
下一篇: How do I create a unique constraint that also allows nulls?
