MySQL LENGTH() > 0 且 NOT NULL 未得到预期结果

标签 mysql select string-length notnull

查看我的结果集,无论我的条件如何,我都会看到一个空白字段。

我尝试选择:

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/

相关文章:

php - MySQL:克隆一张表中的行

mysql - 如何在MySql中转义撇号(单引号)?

Java:showInputDialog 和 ProcessBuilder

java - 有效字符串的长度返回 0

c++ - MySQL C++ 连接器 Unresolved 依赖项 (VS 2015)

php - 如何正确从数据库中检索

amazon-web-services - 在 s3 选择查询中转义单引号

MySQL 条件相反

firefox - 选择框中的文本垂直对齐 - Firefox 问题

java - Kotlin 字符串最大长度? (带有长字符串的 Kotlin 文件无法编译)