Results 1 to 5 of 5
  1. #1
    epb is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Near Chicago
    Posts
    36

    Finding duplicate data ona three field index

    I have a database that needs to have a three field index created to prevent duplicate entries. Problem is that there is already thousands of records and some of these have duplicates across the three fields.

    I created the three field index and on saving the table it would not allow the save because there are already duplicates across the three fields.

    My question is how do I create a query to display these duplicates. The table is [CustOrders]. The fields are [POPart], [PONum] and [POLine]. I believe most of the issue is with [POLine] being duplicated. I just need to see the duplicates or print out their OrderID number so I can look at the record. OrderID is the PK.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Start with an aggregate (GROUP BY) query that counts the occurrence of each 3 field combination.

    SELECT [POPart], [PONum], [POLine], Count(*) As CountKey FROM [CustOrders] GROUP BY [POPart], [PONum], [POLine] WHERE Count(*) > 1;

    If you want to see the OrderID, join that aggregate query to CustOrders table by linking on the 3 fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    epb is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Near Chicago
    Posts
    36
    I am not sure how that is working. I am not too knowledgeable in SQL. I tried putting that line in a query and it says there is an issue with a missing operator and gives the following code:

    Code:
    '[POLine] WHERE Count(*) > 1'
    I am not sure how I join the [OrderID] to that also. I am crawling and not walking when it comes to SQL.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    That's what I get trying to create from memory without testing syntax.
    Instead of WHERE, use HAVING.

    The join will not be on OrderID. In another query, join the aggregate query with the table. The join will be on the 3 compound key fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    epb is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Near Chicago
    Posts
    36
    Thank you June! Using "HAVING" worked...I did not use the JOIN because the handful or records that were duplicates could be found easily without it.

    Thanks again

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

Similar Threads

  1. Replies: 4
    Last Post: 01-14-2016, 02:18 PM
  2. Finding Duplicate Values
    By TimMoffy in forum Forms
    Replies: 4
    Last Post: 11-21-2012, 10:22 PM
  3. Replies: 4
    Last Post: 04-19-2012, 11:01 AM
  4. ummmm... finding duplicate rows
    By mcchung52 in forum Queries
    Replies: 3
    Last Post: 02-07-2012, 03:02 AM
  5. Replies: 37
    Last Post: 08-10-2011, 09:43 AM

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