Results 1 to 3 of 3
  1. #1
    ramindya is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20

    Delete records with dates less than the max date

    I have a table A that has following fields MRN, DATEOFLASTCONTACT, NAME. There is no primary key in this table.

    I want to delete records from the table for the same patient whose date of last contact is less than max date of last contact.
    Example:

    TABLE A: ( BEFORE RUNNING SQL QUERY )
    NAME MRN DATEOFLASTCONTACT
    JOHN 1234 12/12/2012
    JOHN 1234 12/12/2011
    JOHN 1234 11/10/2010

    I need the SQL query that can give me the following output in the same table TABLE A:

    NAME MRN DATEOFLASTCONTACT

    JOHN 1234 12/12/2012

    I also want to create a seperate table TABLE B from the intial table TABLE A as:
    NAME MRN DATEOFLASTCONTACT
    JOHN 1234 12/12/2011
    JOHN 1234 11/10/2010

    Can you let me know the SQL for above ? Thanks !!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ramindya is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    20
    SELECT * FROM HEALTH_HABITS_RAM
    WHERE DateCompleteSurvey = ( SELECT MAX(DateCompleteSurvey) FROM HEALTH_HABITS_RAM as TEST3
    WHERE HEALTH_HABITS_RAM.MRN = TEST3.MRN)
    ORDER BY HEALTH_HABITS_RAM.MRN


    DELETE * FROM HEALTH_HABITS_RAM
    WHERE DateCompleteSurvey < ( SELECT MAX(DateCompleteSurvey) FROM HEALTH_HABITS_RAM as TEST3
    WHERE HEALTH_HABITS_RAM.MRN = TEST3.MRN)


    SELECT * INTO OLD_TEST FROM HEALTH_HABITS_RAM
    WHERE DateCompleteSurvey < ( SELECT MAX(DateCompleteSurvey) FROM HEALTH_HABITS_RAM as TEST3
    WHERE HEALTH_HABITS_RAM.MRN = TEST3.MRN)
    ORDER BY HEALTH_HABITS_RAM.MRN

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

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2012, 02:16 PM
  2. Can't delete records
    By joe1987 in forum Forms
    Replies: 1
    Last Post: 12-01-2011, 06:28 PM
  3. Delete all records
    By stryder09 in forum Access
    Replies: 6
    Last Post: 05-11-2011, 02:07 PM
  4. Replies: 3
    Last Post: 05-03-2011, 01:36 PM
  5. #delete records
    By supernova122 in forum Access
    Replies: 0
    Last Post: 07-08-2009, 08:41 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