Results 1 to 2 of 2
  1. #1
    damngroundhog is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    5

    Delete duplicates from sql query based on import date


    Hello. MS Access and sql user for 2 entire days! I have researched and found out how to delete duplicate records using 2 sql queries. First one
    Code:
     SELECT last(id) as lastid INTO temp_delete FROM tbl1 GROUP BY sourceid HAVING count(sourceid >1);
    Second one
    Code:
     DELETE DISTINCTROW tbl1.* FROM tbl1 INNER JOIN temp_delete ON tbl1.id = temp_delete.lastID;
    Each row of data has an import date. I am looking to compare the import dates and use the older one. IE if one import date is 8/15 and the other is 8/22, i want to keep the 8/15 one. I am unsure how to create a comparison in this. Any help is always duly appreciated. Groundhog

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    The older one of what? Are there multiple same ID values in this data and you want oldest date record for each ID?

    Post sample dataset.
    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.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-16-2017, 04:01 PM
  2. Replies: 6
    Last Post: 06-30-2017, 02:15 PM
  3. Replies: 3
    Last Post: 01-18-2016, 01:55 PM
  4. Remove duplicates based on date in another column
    By mlhend2002 in forum Programming
    Replies: 5
    Last Post: 12-26-2011, 01:47 PM
  5. Replies: 3
    Last Post: 05-03-2011, 01:36 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