Results 1 to 10 of 10
  1. #1
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14

    Arrow Duplicate query with complex delete function

    I've have a duplicate query running on a table containing 1000s of records. I need to retain the highest batch number from the property reference group (the duplicate field). Basically keep the records in red in the example below...




    Property Reference


    Batch

    1070

    354

    1070

    491

    1070

    565

    1070

    581

    1070

    582

    1074

    491

    1074

    565

    1074

    581

    1074

    682

    1075

    353

    1075

    354

    1075

    491



    Hope someone can help. This is my first post on the forum.

    Many thanks in advance.
    Last edited by rushforth; 08-20-2010 at 01:22 AM.

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    SELECT Reference, Batch
    FROM myTable
    GROUP BY max(Batch)

  3. #3
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14
    Thanks. Now I've identified the 'max' in each group of duplicates how do I delete all but the max records?

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    instead of a select query, turn it into a make table. make a new table, delete the old one and rename this to the deleted one. Just make sure you dont need all that data first.

  5. #5
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14
    Thanks again. Unfortunatly the master table, where the dup refs are, has more than the two columns I originally posted. How can I make a new table, with all the fields, with the totals column showing?

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    are all the fields besides the Batch exactly the same?

  7. #7
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14
    No. So I cant set the total of all fields to 'Group By'.

  8. #8
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    On second thought, I honestly think you'd be better off leaving the data and adding a field to the table with an indicator instead of deleting the records. Add a field called "maxBatchInd" then run a query
    UPDATE masterTable
    SET maxBatchInd = "whatever you want here"
    WHERE newTable.reference = masterTable.Reference AND newTable.batch = masterTable.Batch

    This will put an indicator (whatever you set it to) in the maxBatchInd field. You can then query off of the indicator without losing all your data. If you really want to delete the other data, after setting the indicator, you can simply...
    DELETE *
    FROM masterTable
    WHERE maxBatchInd Is Null

  9. #9
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14
    Thanks TheShabz. I'll try this out when I get in to the office. I'll let you know.

  10. #10
    rushforth is offline Novice
    Windows Vista Access 2010 (version 14.0)
    Join Date
    Aug 2010
    Posts
    14
    Thanks, worked a treat!

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

Similar Threads

  1. Replies: 1
    Last Post: 05-21-2010, 02:22 PM
  2. Delete record function
    By Evgeny in forum Programming
    Replies: 6
    Last Post: 04-12-2010, 09:19 PM
  3. Delete record if duplicate
    By rubintheyid in forum Access
    Replies: 8
    Last Post: 03-30-2010, 11:33 AM
  4. Complex Update query
    By niihla10 in forum Queries
    Replies: 1
    Last Post: 08-28-2009, 01:02 PM
  5. Delete duplicate records
    By Zukster in forum Queries
    Replies: 1
    Last Post: 08-26-2009, 03:14 AM

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