best way to eliminate mySQL result column with no value
I have a query that dumps a fairly large joined table into a CVS file. Depending on the input parameters there are circumstances where entire columns wind up being empty. I'm imagining a ham-fisted solution of opening up the CSV file afte开发者_C百科r it's been written, and looping through all the rows, looking for situations where entire columns are empty and then re-writing the file with those columns removed. However, I was hoping there was some shorthand SQL way to not bother to write those columns in the first place. To complicate things just slightly I have a UNION at the top which lays out the column headers in the CSV... I'd need to omit those as well...
Any takers? :)
WHERE NOT NULL
example
SELECT * FROM (
SELECT column_1, column_2, column_3 FROM data
-- convuled query goes here
)
WHERE NOT (column_1 IS NULL AND column_2 IS NULL AND column_3 IS NULL)
-- not all columns should be NULL
If you need to check for empty string instead of NULL
just replace by column_1 <> ''
etc...
精彩评论