Results 1 to 7 of 7
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    243

    Find and delete duplicates

    Hi,
    I have three tables in a database with many to many relationship.
    Click image for larger version. 

Name:	Untitled.png 
Views:	13 
Size:	10.0 KB 
ID:	28560
    tblBooks:
    pkBookId, Booktitle, ISBNNumber...... other fields

    trelBooksKeywords:
    pkBooksWords, fkKeyWords, fkBookId

    tblKeyWords:
    pkKeyWords, KeyWords

    I already have around two hundred records.



    Table tblKeyWords has a lot of duplicates in it.
    How can I delete all these duplicates so as to have the Indexed property of the KeyWords field being set to: Indexed (duplicates NO)

    Khalil
    Attached Thumbnails Attached Thumbnails Capture.JPG  

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you need to create a find duplicates query. See: https://www.gcflearnfree.org/access2...cates-query/1/

    And then delete the duplicate. BACK UP YOUR DATA FIRST
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Khalil,
    What exactly do you consider a duplicate? Please give us an example or 2?
    Can you show us some records from tblKeywords?
    What exactly do you store in field Keywords?

  4. #4
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    243
    Quote Originally Posted by orange View Post
    Khalil,
    What exactly do you consider a duplicate? Please give us an example or 2?
    Can you show us some records from tblKeywords?
    What exactly do you store in field Keywords?

    The table tblKeywords is a table having words or phrases and each word / phrase is supposed to be mentioned only once and there is no need to have them repeated in different rows.
    My mistake from the beginning was that these words were entered as text fields instead of having them as combo boxes where one can select the word (if it does not exist one can add it).
    What I am seeking is to remove the repetitions.
    Attached is a sample showing it.
    Click image for larger version. 

Name:	Duplicates.png 
Views:	12 
Size:	6.7 KB 
ID:	28564
    Khalil

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    use a query something like

    Code:
    DELETE *
    FROM tblKeyWords WHERE pkKeyWords NOT IN (SELECT MIN(pkKeyWords) FROM tblKeyWords T WHERE KeyWords=tblKeyWords.KeyWords)
    Make sure you take a copy of the table first in case you do not get the required result.

    Actually that does not go far enough - before deleting the duplicate records, you need to update the trelBooksKeyWords table to only use the first instance

    make this translation query

    Code:
    SELECT O.pkKeyWords AS OldPK, N.pkKeyWords AS NewPK
    FROM tblKeyWords O INNER JOIN tblKeyWords N ON O.KeyWords=N.KeyWords
    WHERE O.pkKeyWords<>N.pkKeyWords
    In you example this should produce a result of

    OldPK...NewPK
    220......195

    then create an update query

    Code:
    UPDATE trelBooksKeyWords SET pkKeyWords=NewPK
    FROM trelBooksKeyWords INNER JOIN TranslationQuery ON trelBooksKeyWords.pkKeyWords=TranslationQuery.OldPK

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What do you do with misspellings or plural forms etc?
    eg Conflict vs conflicts?

    le comunità cristiane vs comunità cristiana

  7. #7
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    243
    Thanks to all.
    As for the conflicts, some one will revise it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete Duplicates
    By RGatDP in forum Access
    Replies: 1
    Last Post: 05-25-2016, 09:08 AM
  2. Replies: 3
    Last Post: 01-18-2016, 01:55 PM
  3. Delete all duplicates except one
    By Tom123 in forum Queries
    Replies: 5
    Last Post: 02-11-2014, 07:36 AM
  4. Replies: 8
    Last Post: 02-09-2014, 07:25 PM
  5. Replies: 2
    Last Post: 01-24-2012, 02:16 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums