查看我的结果集,无论我的条件如何,我都会看到一个空白字段。
我尝试选择:
SELECT column
FROM table
WHERE LENGTH(column) > 0 AND column IS NOT NULL
我也尝试过:
WHERE LENGTH(column) <> 0 AND column IS NOT NULL
但是,我仍然看到一个空白字段。
在我的 SELECT 中,我尝试检查字段的内容:
SELECT column, LENGTH(column), HEX(column)
等等...
但是,它们分别显示为 0 和看似空的。
我在这里错过了什么?
最佳答案
SELECT
....
FROM contacts as co
JOIN clients as cl
ON co.contact_client = cl.client_oldid
-- this starts a where clause
WHERE cl.client_status = 2
-- ORDER BY ends a WHERE clause, and goes only for ordering:
order by
cl.client_name
AND LENGTH(co.contact_email) > 0 -- so, order by result of this 0 or 1
AND co.contact_email is not null -- then, order by result of this 0 or 1
AND TRIM(co.contact_EMAIL) <> ' -- then, order by result of this 0 or 1
关于MySQL LENGTH() > 0 且 NOT NULL 未得到预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282969/