Results 1 to 8 of 8
  1. #1
    Saisai is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    4

    MS Acces queries or using vba

    Kindly help me in the data, I am having a access table that has EMP ID and Name. I want to delete duplicates, BUT not same name...ie, if the ID is assigned to more than one person then we should delete it. If it is same person, we have to retain it. u

    Output should be only 1003 Vas, because, 1001 is assigned to jack, MAC and John, If 1001 assigned only to Jack, if should be retained, since it is assinged to MAC and JOHN we are deleting it.. kindly help
    ie ,
    EMP ID Name


    1001 Jack
    1001 Jack
    1001 MAc
    1003 Vas
    1001 John

    Output
    EMP ID Name
    1003 Vas

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Try:

    DELETE FROM tablename WHERE EmpID IN (SELECT EmpID FROM tablename GROUP BY EmpID HAVING Count(*)>1)
    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
    Saisai is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    4
    Thank you. But it also deletes the 2nd record of a person which is not assigned to others.. That is if 1001 is not assigned to other person, it should not delete it. 1 person can have multiple records (1001 Sam, 1001 sam) with same name and ID.. When name changes but id is same then delete... That is if 1001 is also assigned to John, then it should delete all record of John and sam

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Okay, try this:
    Code:
    DELETE FROM Table1 
    WHERE EmpID 
    IN (SELECT DistinctIDNAME.EmpID 
          FROM (SELECT DISTINCT Table1.EmpID, Table1.EmpName FROM Table1) AS DistinctIDNAME
          GROUP BY DistinctIDNAME.EmpID
          HAVING Count(EmpName)>1);
    I added two records 1002 Joan and after running query, the 2 Joan and 1 Vas records remain.
    Last edited by June7; 07-18-2022 at 09:04 AM.
    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
    Saisai is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    4
    Thank you it worked well

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Perhaps you should adjust your logic to prevent this to occur
    ".....if the ID is assigned to more than one person then we should delete it."

    Why input garbage, then run a separate process to clean things up??

  7. #7
    Saisai is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2022
    Posts
    4
    Actually it a job databse where one people work on several ids.. And one more thing.. The query takes 10 mins to. Clean up.. Any suggestions to run it quickee

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    See my article on optimising queries Speed Comparison Tests 8 (isladogs.co.uk)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Cross Apply queries in Acces?
    By SAugsburger in forum Queries
    Replies: 5
    Last Post: 04-14-2014, 10:23 AM
  2. Acces 2010
    By Broere69 in forum Access
    Replies: 1
    Last Post: 10-22-2013, 07:52 AM
  3. Is acces what I need
    By jammerculture in forum Access
    Replies: 5
    Last Post: 11-12-2012, 09:15 AM
  4. Acces DB Setup Help.
    By dbalilti in forum Access
    Replies: 4
    Last Post: 06-01-2012, 01:05 PM
  5. acces listbox hatası(acces debug)
    By carso in forum Access
    Replies: 1
    Last Post: 09-22-2009, 04:11 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