MySQL select where column is not empty

后端 未结 13 2135
深忆病人
深忆病人 2020-11-30 18:18

In MySQL, can I select columns only where something exists?

For example, I have the following query:

select phone, phone2
from jewishyellow.users
wh         


        
13条回答
  •  温柔的废话
    2020-11-30 18:34

    Check for NULL and empty string values:

    select phone
    , phone2 
    from users 
    where phone like '813%' 
    and trim(coalesce(phone2, '')) <>''
    

    N.B. I think COALESCE() is SQL standard(-ish), whereas ISNULL() is not.

提交回复
热议问题