在MySQL,我可以选择列只存在的东西吗?

例如,我有以下查询:

select phone, phone2
from jewishyellow.users
where phone like '813%'
and phone2

我试图只选择电话以813开始的行,电话2有一些东西在里面。


当前回答

select phone, phone2 from jewishyellow.users 
where phone like '813%' and phone2 is not null

其他回答

Use:

SELECT t.phone, 
       t.phone2 
  FROM jewishyellow.users t
 WHERE t.phone LIKE '813%' 
   AND t.phone2 IS NOT NULL

你可以使用like操作符通配符来实现:

SELECT t.phone, 
       t.phone2 
FROM jewishyellow.users t
WHERE t.phone LIKE '813%' 
  AND t.phone2 like '[0-9]';

通过这种方式,您可以获得所有具有数字前缀的phone2。

select phone, phone2 from jewishyellow.users 
where phone like '813%' and phone2 is not null

在我的情况下,我有一个varchar列,两个方法的IS NOT NULL & != "没有工作,但以下工作为我。把这个写出来。

SELECT * FROM `db_name` WHERE `column_name` LIKE '%*%'

令人惊讶的是(之前没有人提到过),我们发现下面的条件可以起作用:

WHERE ORD(field_to_check) > 0 

当我们需要排除空值和空值时。 有人知道这种方法的缺点吗?