Results 1 to 11 of 11
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    Delete specific records

    Hi



    I wish to delete records that do not have a field with either "Westbury" or "Chapel Allerton".

    ok I know it would be simpler to do it by hand - only 60 records in table but in the interests of increasing ability thought I'd use a query.

    Simple huh?

    I tried

    Code:
    SELECT tbl_ParishinDatabase.Parish, tbl_ParishinDatabase.ParishID
    FROM tbl_ParishinDatabase
    WHERE (((tbl_ParishinDatabase.Parish)<>"Westbury" Or (tbl_ParishinDatabase.Parish)<>"Chapel Allerton"));
    And it did not work

    cab someon tell me why?

    thanks

    Ian

  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
    Try And rather than Or.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,369
    I think OR is correct since the field likely does not contain both values in the same record. However, a Select query does not delete records.
    Understand that the entire record will be deleted (when you write it correctly), not just the values in the fields you refer to.
    Last edited by Micron; 07-20-2016 at 09:02 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by Micron View Post
    I think OR is correct since the field likely does not contain both values in the same record.
    Or is not correct when the test is <>. If a record is A and thus I want to exclude it, it meets the "OR <> B" test and thus will be included. Every record is either not A or not B.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,369
    I should have given the issue more thought. Was more focused on the Select query part.
    Thanks for the correction.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No worries. It is counter-intuitive, but the <> flips the logic.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    Access autocorrect to <> from NOT

    Hi

    I have not as yet created the delete query but was following advice learnt long ago - ok a few months- to create a working query first before changing it to a delete, update or append.

    So I was trying to take my list of 60 different parishes and delete all records except where the parish name is either westbury or chapel allerton.

    Hence my code.

    As to the learned comments I regret to say I have failed to follow.

    I used Or and a previous attempt showed me that And would not work.

    as to <> if in my query I type Not "Westbury"

    Access changes it to <> "Wesbury"

    and If I type in Not "Westbury" Or "Chapel Allerton"

    Access changes it to <> "Westbury" Or "Chapel Allerton"

    So could someone explain the following posr because I'm sorta lost

    "Or is not correct when the test is <>. If a record is A and thus I want to exclude it, it meets the "OR <> B" test and thus will be included. Every record is either not A or not B."

    THanks

    Ian

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Try

    SELECT tbl_ParishinDatabase.Parish, tbl_ParishinDatabase.ParishID
    FROM tbl_ParishinDatabase
    WHERE (((tbl_ParishinDatabase.Parish)<>"Westbury" AND (tbl_ParishinDatabase.Parish)<>"Chapel Allerton"));
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    Still regretab;y confused

    Hi

    thanks for that, have to admit I don't understand why "And" works, the logic of it escapes me as my logic says that if I use And then both criteria must me met clearly this is the inverse logic refered to!

    cheers

    Ian

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Quote Originally Posted by Jen0dorf View Post
    if I use And then both criteria must me met
    You want both criteria met in this case, do you not?

    You want the value to be not equal to A, AND you want it to be not equal to B.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi

    point taken my logic was flawed.

    After all that I had a mental blowout and thought of another and better way to do what I wanted!!

    Added a field to the main table containing the parish names and made it a yes/no field. That way I can tick each parish as I add it to the database and uses the true attribute to limit a parish list to the ones I've added.

    I must be learning something!!

    cheers

    Ian

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

Similar Threads

  1. Delete does not delete records in evey table
    By LaughingBull in forum Access
    Replies: 5
    Last Post: 09-01-2015, 04:05 PM
  2. Delete Specific Duplicates
    By access360 in forum SQL Server
    Replies: 4
    Last Post: 07-15-2015, 10:22 AM
  3. Replies: 8
    Last Post: 02-09-2014, 07:25 PM
  4. Could not delete from specific table
    By willy292 in forum Queries
    Replies: 1
    Last Post: 07-14-2013, 10:08 AM
  5. Replies: 2
    Last Post: 01-24-2012, 02:16 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