Results 1 to 6 of 6
  1. #1
    krag is offline Medium experience
    Windows 10 Office 365
    Join Date
    May 2014
    Posts
    76

    Remove from one query, all records which have common field values in another query's all records

    I have 2 queries A and B, with similar lists and one common text field X.
    I want to remove from query A all records whose X values are equal to the X values in query B.
    I have made query C, which has both A and B in it but not linked in anyway.
    I have selected all the fields in A.
    For field X, I have set criteria as <>B![X].
    In properties I have set "Unique Records" as Yes but does not have any effect anyway.

    Result is that it is simply opening all the records in A (including the common ones from B) and seems to ignore the criteria altogether.


    Any suggestions would be appreciated.

  2. #2
    Minty is offline VIP
    Windows 11 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Left Join query A to Query B on the x field.
    In the query designer add Query B x field and in the criteria put Is Null

    That should do what you want.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    you also use:

    Code:
    DELETE QueryA.* FROM QueryA WHERE EXISTS (SELECT NULL FROM QueryB Where QueryB.X = QueryA.X);

  4. #4
    krag is offline Medium experience
    Windows 10 Office 365
    Join Date
    May 2014
    Posts
    76
    Minty and jojowhite
    Thanks for the very fast response.
    It worked.
    In fact I had used it long back (pre-corona days) once and totally forgot the trick.
    Thanks again for reminding me.

  5. #5
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    Quote Originally Posted by krag View Post
    Minty and jojowhite
    Thanks for the very fast response.
    It worked.
    In fact I had used it long back (pre-corona days) once and totally forgot the trick.
    Thanks again for reminding me.
    Can you tell us which Query works for you so that others
    who will find this thread will get the right solution.

  6. #6
    Minty is offline VIP
    Windows 11 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I think both will work.
    I suspect but (don't know) that the join might be more efficient than the Exists clause in Access.
    Depends on the Query Plans. A SQL server plan may be the other way around.
    They may even work out to be the same.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 5
    Last Post: 09-24-2021, 10:28 AM
  2. Replies: 7
    Last Post: 03-26-2020, 06:09 AM
  3. Replies: 5
    Last Post: 08-08-2019, 11:10 AM
  4. Replies: 1
    Last Post: 06-20-2017, 09:00 AM
  5. Replies: 1
    Last Post: 06-09-2011, 10:12 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