Is it possible to do a select statement that takes only NOT NULL values?
Right now I am using this:
SELECT * FROM table
And then I have to filter out the null values with a php loop.
Is there a way to do:
SELECT * (that are NOT NULL) FROM table
?
Right now when I select * I get val1,val2,val3,null,val4,val5,null,null etc.... but I just want to get the values that are not null in my result. Is this possible without filtering with a loop?
UNION ... WHERE coln IS NOT NULL
statements but that will scan the table once for each column. MySQL doesn't have anUNPIVOT
operator that would help here. So probably the most efficient way would be to do it in your code. The best you can do is exclude rows where all columns areNULL
. Are you sure your table stucture is normalised? – Barbed