Alex Rivera | Logout

Need help selecting non-empty column values from MySQL

Asked 2011-08-04T19:11:42.003
30

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 because I have empty cells rather that having NULL in the void cell.

Edit
Report

1 Answer

64

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) <> ''
answered 2011-08-04T19:12:45.560

Your Answer