MySQL select where column is not empty
In MySQL, can I select columns only where something exists?
For example, I have the following query:
select phone, phone2
from jewishyellow.users
where phone like '813%'
and phone2
I'm trying to select only the rows where phone starts with 813 and phone2 has something in it.
 Compare value of phone2 with empty string:  
select phone, phone2 
from jewishyellow.users 
where phone like '813%' and phone2<>''
 Note that NULL value is interpreted as false .  
 To check if field is NULL use IS NULL , IS NOT NULL operators.  
MySql reference http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html
 Check for NULL and empty string values:  
select phone
, phone2 
from users 
where phone like '813%' 
and trim(coalesce(phone2, '')) <>''
NB I think COALESCE() is SQL standard(-ish), whereas ISNULL() is not.
链接地址: http://www.djcxy.com/p/94242.html上一篇: 如何更新TSQL中由游标读取的列
下一篇: MySQL选择哪个列不是空的
