Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Duplicates

Status
Not open for further replies.

pradchal1

Programmer
Nov 10, 2004
31
FR
In a situation like the following:

A 05-05-2005 Blue
A 05-05-2005 Red
A 05-05-2005 Red
A 04-04-2004 Red
B 05-05-2005 Red
B 05-05-2005 Red
B 04-04-2004 Yello

How do I get the following table:

A 05-05-2005 Red
A 05-05-2005 Red
A 05-05-2005 Blue
B 05-05-2005 Red
B 05-05-2005 Red

Note: Basically I am trying to get the highest date for each color. If it is present more than once, I want both the instances.

Thanks.
 
Just group by those fields.

Dr. Sql
goEdeveloper@yahoo.com
Good Luck.
 
Code:
select * 
 from t as q
where dateColumn in
  (select max(dateColumn)
    from t
    where t.colour = q.colour)
 
select col1,col2,col3 from table
group by col1,col2,col3

Should give you what you are looking in your case

Dr. Sql
goEdeveloper@yahoo.com
Good Luck.
 
Tips from SwampBoogie worked. Dr.sql's logic does not work here.
Thanks to both of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top