开发者

Need help selecting non-empty column values from MySQL

开发者 https://www.devze.com 2023-03-25 03:45 出处:网络
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?

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?

Here is my attempt:

SELECT * FROM `table` WHERE column IS NOT NULL

This does not filter be开发者_如何学JAVAcause I have empty cells rather that having NULL in the void cell.


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 ''

SELECT * FROM `table` WHERE column IS NOT NULL AND TRIM(column) <> ''


A alternate approach that also handles blank spaces in a column as well as null:

SELECT * FROM `table` WHERE TRIM(column) > ''
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号