PC Review


Reply
Thread Tools Rate Thread

Auto deletion of duplicates

 
 
mrwhitescotland
Guest
Posts: n/a
 
      10th Sep 2008
Hi there.

I have two tables and want to delete duplicates.

ie if they appear in table A and table B then I want BOTH entries to be
deleted and be left with only those who only appear in either A or B.

Have absolutely no experience of SQL and basic access, so any help would be
gratefully received.

Thanks
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      10th Sep 2008
How do you identify that a record in A is a duplicate of a record in B?

If you can do so using just one field then

DELETE
FROM A
WHERE A.IdentifierField IN
(SELECT B.IdentifierField
FROM B)

DELETE
FROM B
WHERE B.IdentifierField IN
(SELECT A.IdentifierField
FROM A)

Warning this permanently deletes the records. If you want to return a
record set that shows the two set of records that can be done.


'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


mrwhitescotland wrote:
> Hi there.
>
> I have two tables and want to delete duplicates.
>
> ie if they appear in table A and table B then I want BOTH entries to be
> deleted and be left with only those who only appear in either A or B.
>
> Have absolutely no experience of SQL and basic access, so any help would be
> gratefully received.
>
> Thanks

 
Reply With Quote
 
Lord Kelvan
Guest
Posts: n/a
 
      10th Sep 2008
if you want AUTO delete you want a trigger and access dosnt support
triggers so you have to do it manually every time you want to clean
the data up

Regards
Kelvan
 
Reply With Quote
 
mrwhitescotland
Guest
Posts: n/a
 
      11th Sep 2008
Thanks John,

I will give it a try and see what happens.

Cheers

Ed

"John Spencer" wrote:

> How do you identify that a record in A is a duplicate of a record in B?
>
> If you can do so using just one field then
>
> DELETE
> FROM A
> WHERE A.IdentifierField IN
> (SELECT B.IdentifierField
> FROM B)
>
> DELETE
> FROM B
> WHERE B.IdentifierField IN
> (SELECT A.IdentifierField
> FROM A)
>
> Warning this permanently deletes the records. If you want to return a
> record set that shows the two set of records that can be done.
>
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007
> Center for Health Program Development and Management
> University of Maryland Baltimore County
> '====================================================
>
>
> mrwhitescotland wrote:
> > Hi there.
> >
> > I have two tables and want to delete duplicates.
> >
> > ie if they appear in table A and table B then I want BOTH entries to be
> > deleted and be left with only those who only appear in either A or B.
> >
> > Have absolutely no experience of SQL and basic access, so any help would be
> > gratefully received.
> >
> > Thanks

>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      11th Sep 2008
I was a bit unclear in my post. The SQL I posted would have to be two
separate queries in Access.

AND if you were just trying to return the result without deleting
records then you could use a UNION query.

SELECT A.*
FROM A LEFT JOIN B
ON A.IdentifierField = B.IdentifierField
WHERE B.IdentifierField is Null

UNION ALL

SELECT B.*
FROM A RIGHT JOIN B
ON A.IdentifierField = B.IdentifierField
WHERE A.IdentifierField is Null

'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================


mrwhitescotland wrote:
> Thanks John,
>
> I will give it a try and see what happens.
>
> Cheers
>
> Ed
>
> "John Spencer" wrote:
>
>> How do you identify that a record in A is a duplicate of a record in B?
>>
>> If you can do so using just one field then
>>
>> DELETE
>> FROM A
>> WHERE A.IdentifierField IN
>> (SELECT B.IdentifierField
>> FROM B)
>>
>> DELETE
>> FROM B
>> WHERE B.IdentifierField IN
>> (SELECT A.IdentifierField
>> FROM A)
>>
>> Warning this permanently deletes the records. If you want to return a
>> record set that shows the two set of records that can be done.
>>
>>
>> '====================================================
>> John Spencer
>> Access MVP 2002-2005, 2007
>> Center for Health Program Development and Management
>> University of Maryland Baltimore County
>> '====================================================
>>
>>
>> mrwhitescotland wrote:
>>> Hi there.
>>>
>>> I have two tables and want to delete duplicates.
>>>
>>> ie if they appear in table A and table B then I want BOTH entries to be
>>> deleted and be left with only those who only appear in either A or B.
>>>
>>> Have absolutely no experience of SQL and basic access, so any help would be
>>> gratefully received.
>>>
>>> Thanks

 
Reply With Quote
 
mrwhitescotland
Guest
Posts: n/a
 
      11th Sep 2008
Hi John,

I have run a test on two sample tables and I have managed to get the result
I was looking for.

Thanks a lot for the quick response and the excellent advice, it has made a
huge difference.

Cheers

Ed

"John Spencer" wrote:

> I was a bit unclear in my post. The SQL I posted would have to be two
> separate queries in Access.
>
> AND if you were just trying to return the result without deleting
> records then you could use a UNION query.
>
> SELECT A.*
> FROM A LEFT JOIN B
> ON A.IdentifierField = B.IdentifierField
> WHERE B.IdentifierField is Null
>
> UNION ALL
>
> SELECT B.*
> FROM A RIGHT JOIN B
> ON A.IdentifierField = B.IdentifierField
> WHERE A.IdentifierField is Null
>
> '====================================================
> John Spencer
> Access MVP 2002-2005, 2007
> Center for Health Program Development and Management
> University of Maryland Baltimore County
> '====================================================
>
>
> mrwhitescotland wrote:
> > Thanks John,
> >
> > I will give it a try and see what happens.
> >
> > Cheers
> >
> > Ed
> >
> > "John Spencer" wrote:
> >
> >> How do you identify that a record in A is a duplicate of a record in B?
> >>
> >> If you can do so using just one field then
> >>
> >> DELETE
> >> FROM A
> >> WHERE A.IdentifierField IN
> >> (SELECT B.IdentifierField
> >> FROM B)
> >>
> >> DELETE
> >> FROM B
> >> WHERE B.IdentifierField IN
> >> (SELECT A.IdentifierField
> >> FROM A)
> >>
> >> Warning this permanently deletes the records. If you want to return a
> >> record set that shows the two set of records that can be done.
> >>
> >>
> >> '====================================================
> >> John Spencer
> >> Access MVP 2002-2005, 2007
> >> Center for Health Program Development and Management
> >> University of Maryland Baltimore County
> >> '====================================================
> >>
> >>
> >> mrwhitescotland wrote:
> >>> Hi there.
> >>>
> >>> I have two tables and want to delete duplicates.
> >>>
> >>> ie if they appear in table A and table B then I want BOTH entries to be
> >>> deleted and be left with only those who only appear in either A or B.
> >>>
> >>> Have absolutely no experience of SQL and basic access, so any help would be
> >>> gratefully received.
> >>>
> >>> Thanks

>

 
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
how do I highlight duplicates cells in excell prior to deletion =?Utf-8?B?UGF1bCBC?= Microsoft Excel Worksheet Functions 6 21st Aug 2007 12:08 PM
Auto time deletion Blair Microsoft Access Form Coding 0 14th Jan 2007 06:37 PM
Row deletion and auto filter RMJames Microsoft Excel Programming 1 15th Mar 2006 12:40 PM
deletion of duplicates records =?Utf-8?B?ZGVsZXRlIGR1cGxpY2F0ZXM=?= Microsoft Access 2 11th Feb 2006 10:32 PM
Auto row deletion rogeraw Microsoft Excel Discussion 2 29th Jul 2005 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:54 PM.