Results 1 to 2 of 2
  1. #1
    Ghoztrider is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    2

    Select maximum price for each duplicate set of records in "Find Duplicates Query"

    I've created a find duplicates query with "part number" and "price" fields. Part Number being the duplicate value field. I need to be able to find the highest price for each set of duplicate records and delete the rest. Example......

    Part#: Price:
    Widget1 $25.00
    Widget1 $32.00


    Widget1 $15.00

    I need to keep Widget1 for $32.00 and delete the rest. Any direction would be appreciated. Thank you.

  2. #2
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Okay, lots of possibilities here, depending on the rest of the record. Here's one.

    What I'd suggest is that you do this in a test version of your database -

    (1) create a new table by copying the old table, structure only. Let's assume that it had a layout something like this
    Code:
    OldTable / NewTable layout
        PART#    Number
        Field1   Text
        Field2   Text
        Price    Currency
        Field3   Number
        Field4   Text
        Field5   Memo
    (2) Now you make an append query with a group by. Use Max() to get your price, use (First) for everything else.
    Code:
    INSERT INTO NewTable
      SELECT 
        PART#,
        First(Field1), 
        First(Field2), 
        MAX(Price),
        First(Field3), 
        First(Field4), 
        First(Field5) 
    FROM 
       OldTable 
    GROUP BY
       PART#;
    3) Now check to make sure that the resulting table is reasonable. Especially check memo fields to make sure they haven't been truncated.

    4) If that worked, then you can back up the old table in your live database, delete all the data from it and then copy your new table into it.

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

Similar Threads

  1. Replies: 1
    Last Post: 08-12-2013, 09:34 AM
  2. Replies: 1
    Last Post: 07-26-2013, 11:42 AM
  3. Replies: 1
    Last Post: 11-27-2012, 02:49 AM
  4. Replies: 1
    Last Post: 10-08-2012, 09:01 AM
  5. Replies: 3
    Last Post: 02-23-2010, 06:32 PM

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