PC Review


Reply
Thread Tools Rate Thread

Deleting one record from the result of duplicate query

 
 
=?Utf-8?B?bmFkaW5l?=
Guest
Posts: n/a
 
      6th Nov 2006
My Issue is that as a result of an append query I get duplicate records. The
Duplicate record has an auto number so I only want to delete the oldest
record which would be the min Value ,but I cannot get the query to work . Any
suggestions

Thanks
--
Nadine
 
Reply With Quote
 
 
 
 
Granny Spitz via AccessMonster.com
Guest
Posts: n/a
 
      6th Nov 2006
nadine wrote:
> My Issue is that as a result of an append query I get duplicate records.


First make a backup of your table in case something goes wrong. You must
next determine which columns identify *duplicates* and place the primary key
or a unique index (disallowing nulls) on this combination of columns, but
*after* you remove these duplicates. In this example, ID is the autonumber
and all duplicate records with the same FirstName and LastName are removed,
leaving only the most recent records:

DELETE *
FROM TableA
WHERE (ID NOT IN
(SELECT MAX(ID) AS MaxID
FROM TableA
GROUP BY FirstName, LastName
HAVING COUNT(*) > 1)) AND
(ID NOT IN
(SELECT MIN(ID) AS MinID
FROM TableA
GROUP BY FirstName, LastName
HAVING COUNT(*) = 1));

After running this query the primary key should be placed on the LastName and
FirstName columns to prevent further duplicates.

--
Message posted via http://www.accessmonster.com

 
Reply With Quote
 
DimmickT
Guest
Posts: n/a
 
      4th Sep 2008
This solved my problem also. Thanks
--
DimmickT


"Granny Spitz via AccessMonster.com" wrote:

> nadine wrote:
> > My Issue is that as a result of an append query I get duplicate records.

>
> First make a backup of your table in case something goes wrong. You must
> next determine which columns identify *duplicates* and place the primary key
> or a unique index (disallowing nulls) on this combination of columns, but
> *after* you remove these duplicates. In this example, ID is the autonumber
> and all duplicate records with the same FirstName and LastName are removed,
> leaving only the most recent records:
>
> DELETE *
> FROM TableA
> WHERE (ID NOT IN
> (SELECT MAX(ID) AS MaxID
> FROM TableA
> GROUP BY FirstName, LastName
> HAVING COUNT(*) > 1)) AND
> (ID NOT IN
> (SELECT MIN(ID) AS MinID
> FROM TableA
> GROUP BY FirstName, LastName
> HAVING COUNT(*) = 1));
>
> After running this query the primary key should be placed on the LastName and
> FirstName columns to prevent further duplicates.
>
> --
> Message posted via http://www.accessmonster.com
>
>

 
Reply With Quote
 
jose
Guest
Posts: n/a
 
      5th Sep 2008


"DimmickT" <(E-Mail Removed)> wrote in message
news:603067B1-1589-4A46-83CD-(E-Mail Removed)...
> This solved my problem also. Thanks
> --
> DimmickT
>
>
> "Granny Spitz via AccessMonster.com" wrote:
>
>> nadine wrote:
>> > My Issue is that as a result of an append query I get duplicate
>> > records.

>>
>> First make a backup of your table in case something goes wrong. You must
>> next determine which columns identify *duplicates* and place the primary
>> key
>> or a unique index (disallowing nulls) on this combination of columns, but
>> *after* you remove these duplicates. In this example, ID is the
>> autonumber
>> and all duplicate records with the same FirstName and LastName are
>> removed,
>> leaving only the most recent records:
>>
>> DELETE *
>> FROM TableA
>> WHERE (ID NOT IN
>> (SELECT MAX(ID) AS MaxID
>> FROM TableA
>> GROUP BY FirstName, LastName
>> HAVING COUNT(*) > 1)) AND
>> (ID NOT IN
>> (SELECT MIN(ID) AS MinID
>> FROM TableA
>> GROUP BY FirstName, LastName
>> HAVING COUNT(*) = 1));
>>
>> After running this query the primary key should be placed on the LastName
>> and
>> FirstName columns to prevent further duplicates.
>>
>> --
>> Message posted via http://www.accessmonster.com
>>
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting duplicate records obtained from a duplicate query Paul Microsoft Access Queries 4 16th Dec 2009 06:29 AM
Duplicate query result newbie help Microsoft Access Getting Started 1 8th Jan 2007 08:49 PM
Duplicate records in Query Result david.moore@uuplc.co.uk Microsoft Access Queries 4 17th Oct 2006 06:53 PM
Deleting a duplicate record without deleting the data related. =?Utf-8?B?SGVhdGhlck1pY2hlbGxl?= Microsoft Access 3 12th Mar 2005 03:54 PM
Deleting a record follow by Adding a record will result in getting wrong Index Key problem =?Utf-8?B?TGlzYSBKb25lcw==?= Microsoft VB .NET 0 30th Apr 2004 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:20 PM.