Page 1 of 1

Query to get the max date of each code

PostPosted: Fri Mar 06, 2015 12:14 am
by vegafacundodaniel
Hello,

I need some help please.

I have this table

Code Date
A 01/01/2011
A 03/02/2012
A 05/02/2014
A 10/01/2015
B 01/01/2012
B 04/08/2013
B 01/06/2014
C 01/07/2015


I need to get as result:

A 10/01/2015
B 01/06/2014
C 01/07/2015

I'd to know what is the query to obtain that result.

Thanks in advance

Re: Query to get the max date of each code

PostPosted: Wed Jun 17, 2015 1:42 am
by alexm
Hi vegafacundodaniel,

the answer lies in the subject of your thread ;)

DB2 offers you the max() aggregate function. If you add a 'group by' clause to the query, it will work as desired:

select code ,max(datecol)
from   table1
group  by code


Regards,
alexm