Lets say that I have a table named test like this:
ID DATE
1 '2013-01-26'
1 NULL
1 '2013-03-03'
2 '2013-02-23'
2 '2013-04-12'
2 '2013-05-02'
And I would like to get from this table :
ID DATE
1 NULL
2 '2013-05-02'
Here is my query:
select ID, max(DATE)
from test
group by ID
Problem is that MYSQL ignores NULL values and returns me
ID DATE
1 '2013-03-03'
2 '2013-05-02'
How can i do so when there is a NULL it takes the MAX as NULL?
FYI
NULL
is ignored when used inaggregation
function.Null is not a value or a number it's just null. This is why you use "where col1 is null" and not "col1 = null". The workaround is to use IFNULL and set a really high value.
Give this a shot:
You could use an IF statement: