Results 1 to 6 of 6
  1. #1
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17

    Syntax Error in my Query Code

    I keep getting a syntax error in my query code and I'm having trouble finding it.

    Code:
    DELETE *
    FROM [Student_ID] As [90Hour_MainTable]
    WHERE Exists (SELECT * FROM 90Hour_MainTable WHERE 90Hour_MainTable.Student_ID = Fall2011Grads.StudentID);
    90Hour_MainTable and Fall2011Grads are my tables, and Student_ID and StudentID are my two fields. I'm trying to delete records from the 90Hour table that are in the Fall2011Grads table. Any tips or help is appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Since DELETE sql deletes records from table there is no need to select a field:

    DELETE FROM [90Hour_MainTable] ...
    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
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    For what I'm trying to do, I'm trying to delete the PK so that the rest of the records in that field get deleted. And there is a syntax error with the WHERE clause:


    WHERE Exists (SELECT * FROM 90Hour_MainTable WHERE 90Hour_MainTable.Student_ID = Fall2011Grads.StudentID);

    ?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    This phrase "rest of the records in that field get deleted" doesn't make sense to me.

    DELETE doesn't delete FROM fields, it deletes FROM table: DELETE FROM tablename WHERE records match criteria;

    I can't see anything wrong with the WHERE clause.
    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
    PPat is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    17
    I mean that rest of the records associated with that PK get deleted. If that code doesn't make sense, how would you change it? (I'm sorry, I'm still learning, and thank you for your help).

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Then the PK must be in the WHERE clause.

    DELETE FROM tablename WHERE Student_ID = student ID here

    But that's what the EXISTS (SELECT ...) is supposed to do - retrieved a set of all Student_IDs for deletion. Might need to specify the Student_ID field instead of using * in the subquery.

    Deleting records is not something I do often so sorry for the vagueness.

    Review http://www.techonthenet.com/sql/delete.php
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Replies: 4
    Last Post: 07-25-2012, 04:01 AM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. syntax error in query
    By zoe.ohara in forum Queries
    Replies: 6
    Last Post: 04-23-2011, 04:58 AM
  5. Replies: 3
    Last Post: 10-15-2010, 11:17 AM

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