SQL question: grouping all duplicates with order by

Database

SQL question: grouping all duplicates with order by

Hello,

I am searching for an efficient way to get unique values from a table whereby duplicates should only be represented by a single row (determined by an order by clause).

Example Table
ID2 Code Date1 Date2
2 ABC 01-01-2006 01-01-2008
2 ABC 01-01-2005 01-01-2006
2 BBB 01-01-2005 01-01-2006
3 CDE 01-01-2006 01-01-2008

The result should be:
ID2 Code Date1 Date2
2 ABC 01-01-2006 01-01-2008
3 BBB 01-01-2005 01-01-2006

So what I would like to have is something like

select *
from table2
group by id2
order by code asc, date1 desc, date2, desc

Any help is highly appreciated.

Best regards,
Mo
1 REPLY

Re: SQL question: grouping all duplicates with order by

Hi,

you can forget about my question, as Teradata supports the necessary analytical functions. However it would be interesting to know how to do it without them :-)

Best regards,
Mo