Query to get the max date of each code



IBM's flagship relational database management system

Query to get the max date of each code

Postby vegafacundodaniel » Fri Mar 06, 2015 12:14 am

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
vegafacundodaniel
 
Posts: 61
Joined: Tue Jul 20, 2010 4:27 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Query to get the max date of each code

Postby alexm » Wed Jun 17, 2015 1:42 am

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
User avatar
alexm
 
Posts: 35
Joined: Wed Oct 13, 2010 6:40 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post