Results 1 to 5 of 5
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181

    Subquery - Syntax Error In Expression


    I am trying to use a subquery to define a list to delete. The purpose of this code is to delete duplicates in tblAmazonOrderInput2.

    Both queries have the same syntax error: Syntax error in query expression: 'EXISTS (SELECT * FROM qryAmazonOrderInput-Dedupe WHERE qryAmazonOrderInput-Dedupe.ID = tblAmazonOrderInput2.ID)'

    Code:
    DELETE tblAmazonOrderInput2.*
    FROM tblAmazonOrderInput2 
    WHERE EXISTS (SELECT * FROM qryAmazonOrderInput-Dedupe WHERE qryAmazonOrderInput-Dedupe.ID = tblAmazonOrderInput2.ID);
    Code:
    SELECT tblAmazonOrderInput2.*
    FROM tblAmazonOrderInput2 
    WHERE EXISTS (SELECT * FROM qryAmazonOrderInput-Dedupe WHERE qryAmazonOrderInput-Dedupe.ID = tblAmazonOrderInput2.ID);

  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,521
    The dash would require the name to be bracketed for starters. I've never used the EXISTS syntax; wouldn't a join work there?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Brackets on the query name was the problem, thanks for the help!

    Solution:
    Code:
    DELETE tblAmazonOrderInput2.*
    FROM tblAmazonOrderInput2 
    WHERE [ID] IN 
    (SELECT ID FROM [qryAmazonOrderInput-Dedupe]);
    I had some earlier issues with a join that were frustrating, and decided to go at it from a WHERE clause instead. I'm glad the code works, even though it's not 100% optimized.

  4. #4
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    It looks like an underscore is more friendly than a dash/hyphen. I think I'll make that change to save any future developers some headache!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help! Yes, I think anything other than an underscore will require the brackets. Personally I don't like the underscore, but that's probably because I can't type it without stopping and looking.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 09-10-2014, 11:30 AM
  2. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  3. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  4. Syntax error in query expression
    By That_Guy in forum Programming
    Replies: 3
    Last Post: 08-17-2012, 09:01 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 PM

Tags for this Thread

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