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

Duplicates Query 1

Status
Not open for further replies.

pullingteeth

Programmer
Sep 26, 2003
128
US
Hello, I have a table as follows:

User
Item
Event
Timestamp


Due to a coding error, the table has several hundred duplicate rows, as follows:

User / Item / Event / Timestamp

Joe / 1 / A / 5/26/4 12:34
Peter / 1 / A / 5/26/4 12:45

Janice / 4 / B / 5/27/4 8:19
Sherry / 4 / B / 5/27/4 8:26

(The item and event details are duplicated; the user and timestamp details are different.)

I'd like to write a query to find all of the second rows of each pair (second defined as "has later timestamp") in order to delete them. How would you approach this?

Thanks

 
Something like this ?
SELECT B.* FROM yourTable A INNER JOIN yourTable B
ON (A.Item=B.Item) AND (A.Event=B.Event)
WHERE B.Timestamp>A.Timestamp;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top