If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Deleting double records with SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-16-02, 08:08
EvE EvE is offline
Registered User
 
Join Date: Aug 2002
Location: Holland
Posts: 16
Deleting double records with SQL

I have an Access-db with approx 5000 records. Many of these records are double and I want to get rid of them. One of those records will have to stay. How can I do that?

Id code opleidingsnaam
1 4406 Accountancy
2 4406 Accountancy
3 4406 Accountancy
Reply With Quote
  #2 (permalink)  
Old 10-16-02, 08:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
delete from yourtable
where id not in
( select min(id) from yourtable
group by code )

make a backup copy first, just in case (and also to compare to afterwards, to convince yourself it worked)

rudy
http://rudy.ca/
Reply With Quote
  #3 (permalink)  
Old 10-16-02, 10:54
EvE EvE is offline
Registered User
 
Join Date: Aug 2002
Location: Holland
Posts: 16
It does not work. What went wrong?
Reply With Quote
  #4 (permalink)  
Old 10-16-02, 11:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
please show the sql, and explain how it didn't work

thanks

rudy
Reply With Quote
  #5 (permalink)  
Old 10-22-02, 08:21
krishan_mahesh krishan_mahesh is offline
Registered User
 
Join Date: Oct 2002
Location: New Delhi, India
Posts: 2
Arrow

Please try it :

Delete from <Table Name> where count(code) > 1

Hope that u will get rid of duplicates.
Thanks.
Reply With Quote
  #6 (permalink)  
Old 10-22-02, 09:14
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
where count(code)>1 is not valid syntax

eve, did you try the query i gave you?


rudy
Reply With Quote
  #7 (permalink)  
Old 10-22-02, 12:54
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
Try the following:

delete from table1 as a
where id not in (select min(id) from table1 as b where a.code= b.code)
Reply With Quote
  #8 (permalink)  
Old 08-26-03, 08:25
Erik_SRJV Erik_SRJV is offline
Registered User
 
Join Date: Aug 2003
Posts: 1
Quote:
Originally posted by r937
where count(code)>1 is not valid syntax

eve, did you try the query i gave you?


rudy
should be HAVING count(code)>1
but it deletes without leaving one

the query rnealejr sent works for me; tx!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On