A little hard to explain and it may be a little confusing.
I have a table with following fields:
PK (AutoNumber)
UserFK (Number)
SPS(text)
obj (text)
Lst (text)
I need a query that finds all the records that all fields (except PK) are the same, keeps the record with the largest PK, and deletes the rest.
In above sample data:
100 - 108 - 109 are duplicated. (all fields except PK are the same)
100 - 108 has to be deleted, 109 will remain (because it's the largest PK)
(107 is not duplicated, because SPS field is different) No action is necessary for this record.
101 - 102 - 103 - 105 - 106 are duplicated. (all fields except PK are the same)
101 - 102 - 103 - 105 has to be deleted, 106 will remain (because it's the largest PK)
(104 is not duplicated, because UserFK field is different) No action is necessary for this record.
If mixing a find duplicate with a delete query is not possible, a query that shows the duplicates can help too.
I talked to my supervisor to allow me to export a part of data to offer here, but unfortunately I wasn't able to get his OK.
Note : At present, I've written a function to find and delete these records, but since the table has a little less than a million records, I thought a query may be a wiser idea. ( If possible at all)
Thanks for any kind of help.
I have a table with following fields:
PK (AutoNumber)
UserFK (Number)
SPS(text)
obj (text)
Lst (text)
I need a query that finds all the records that all fields (except PK) are the same, keeps the record with the largest PK, and deletes the rest.
PK | UserFK | SPS | obj | lst |
---|---|---|---|---|
100 | 10 | Layout | Equations | 4 |
101 | 6 | Base | Body | 59 |
102 | 6 | Base | Body | 59 |
103 | 6 | Base | Body | 59 |
104 | 90 | Base | Body | 59 |
105 | 6 | Base | Body | 59 |
106 | 6 | Base | Body | 59 |
107 | 10 | Planes | Equations | 4 |
108 | 10 | Layout | Equations | 4 |
109 | 10 | Layout | Equations | 4 |
In above sample data:
100 - 108 - 109 are duplicated. (all fields except PK are the same)
100 - 108 has to be deleted, 109 will remain (because it's the largest PK)
(107 is not duplicated, because SPS field is different) No action is necessary for this record.
101 - 102 - 103 - 105 - 106 are duplicated. (all fields except PK are the same)
101 - 102 - 103 - 105 has to be deleted, 106 will remain (because it's the largest PK)
(104 is not duplicated, because UserFK field is different) No action is necessary for this record.
If mixing a find duplicate with a delete query is not possible, a query that shows the duplicates can help too.
I talked to my supervisor to allow me to export a part of data to offer here, but unfortunately I wasn't able to get his OK.
Note : At present, I've written a function to find and delete these records, but since the table has a little less than a million records, I thought a query may be a wiser idea. ( If possible at all)
Thanks for any kind of help.
Last edited: