I have a MySQL table which has about 30 columns. One column has empty values for the majority of the table. How can I use a MySQL command to filter out the items which do have values in the table?
我有一个MySQL表,大约有30列。对于表的大部分,一列具有空值。如何使用MySQL命令过滤掉表中包含值的项?
Here is my attempt:
这是我的尝试:
SELECT * FROM `table` WHERE column IS NOT NULL
This does not filter because I have empty cells rather that having NULL
in the void cell.
这不会过滤,因为我有空单元格,而不是在void单元格中有NULL。
2 个解决方案
#1
45
Also look for the columns not equal to the empty string ''
还要查找不等于空字符串的列''
SELECT * FROM `table` WHERE column IS NOT NULL AND column <> ''
If you have fields containing only whitespace which you consider empty, use TRIM()
to eliminate the whitespace, and potentially leave the empty string ''
如果您的字段只包含您认为为空的空格,请使用TRIM()来消除空格,并可能留下空字符串''
SELECT * FROM `table` WHERE column IS NOT NULL AND TRIM(column) <> ''
#2
7
A alternate approach that also handles blank spaces in a column as well as null:
另一种方法也可以处理列中的空格以及null:
SELECT * FROM `table` WHERE TRIM(column) > ''
#1
45
Also look for the columns not equal to the empty string ''
还要查找不等于空字符串的列''
SELECT * FROM `table` WHERE column IS NOT NULL AND column <> ''
If you have fields containing only whitespace which you consider empty, use TRIM()
to eliminate the whitespace, and potentially leave the empty string ''
如果您的字段只包含您认为为空的空格,请使用TRIM()来消除空格,并可能留下空字符串''
SELECT * FROM `table` WHERE column IS NOT NULL AND TRIM(column) <> ''
#2
7
A alternate approach that also handles blank spaces in a column as well as null:
另一种方法也可以处理列中的空格以及null:
SELECT * FROM `table` WHERE TRIM(column) > ''