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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reporting problem

Status
Not open for further replies.

BobBob10

Programmer
Apr 24, 2005
57
GB
Hi there I have the following dataset,

ref to_date ref1
35447 2006-03-24 00:00:00.000 -1
54001 2006-03-24 00:00:00.000 -6
54001 2007-03-24 00:00:00.000 -8
54201 2006-12-31 00:00:00.000 -990

From this record set I want 3 rows, first, third and fourth. I don't need the second due to the refernce number being the same as the third, but the third line the date is greater than the second.

Does anyone know the SQL for this, I need to keep all three columns.

Cheers

Bob
 
SELECT ref, to_date, ref1 FROM tbl
inner join

(SELECT ref as X, MAX(to_date) as y
FROM tbl
GROUP BY X) AS tbltbl
ON tbltbl.X=tbl.ref and tbltbl.Y=tbl.to_date

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top