Home All Groups Group Topic Archive Search About

Table load with duplicates on Primary Key in import file

Author
6 Jan 2006 6:08 PM
CompDog
I am attempting to load a table with a file that has duplicates on a
composite primary key and only want to keep the newest record by a date
field.  Is there a way to do this with a query or will I need to set up
a series of temp tables to accomplish the task.
I also need to load subsequent files with duplicates on existing
records in the table keeping only the newest record as per the same
date field.

Any help with either or both would be appreciated.

Author
7 Jan 2006 8:46 AM
Jens
SELECT * from SomeTable
INNER JOIN
(
    SELECT
        IDCol1,
        IDCol2,
        --...other id columns
        MAX(Datecolum) AS MaxDate
    FROM SomeTable
    GROUP BY
            IDCol1,
            IDCol2
            --...other id columns
) SubQuery
ON    SubQuery.IDCol1 = SOmeTable.IDCol1
    SubQuery.IDCol2 = SOmeTable.IDCol2
    SubQuery.MaxDate = SOmeTable.Datecolum


HTH, Jens Suessmeyer.

AddThis Social Bookmark Button