在MySQL,我可以选择列只存在的东西吗?
例如,我有以下查询:
select phone, phone2
from jewishyellow.users
where phone like '813%'
and phone2
我试图只选择电话以813开始的行,电话2有一些东西在里面。
在MySQL,我可以选择列只存在的东西吗?
例如,我有以下查询:
select phone, phone2
from jewishyellow.users
where phone like '813%'
and phone2
我试图只选择电话以813开始的行,电话2有一些东西在里面。
当前回答
要检查字段是否为空,请使用is NULL, is NOT NULL操作符。
MySql参考http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html
其他回答
要检查字段是否为空,请使用is NULL, is NOT NULL操作符。
MySql参考http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html
SELECT phone, phone2
FROM jewishyellow.users
WHERE phone like '813%' and (phone2 <> "");
可能需要一些调整,这取决于您的默认值是什么。如果你允许Null填充,那么你可以做“Not Null”代替,这显然更好。
Use:
SELECT t.phone,
t.phone2
FROM jewishyellow.users t
WHERE t.phone LIKE '813%'
AND t.phone2 IS NOT NULL
在我的情况下,我有一个varchar列,两个方法的IS NOT NULL & != "没有工作,但以下工作为我。把这个写出来。
SELECT * FROM `db_name` WHERE `column_name` LIKE '%*%'
如果phone2字段中有空格,则可以使用IFNULL和TRIM函数忽略这些记录:
SELECT phone, phone2
FROM jewishyellow.users
WHERE phone LIKE '813%'
AND TRIM(IFNULL(phone2,'')) <> '';