Results 1 to 8 of 8
  1. #1
    SEMich is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    4

    Delete Query using two tables

    Hi,

    I would like to delete records that are in one table but not the other, but keep getting a message saying:
    that you must pecify the table that contains the records you want to delete.

    Here is the sql code:

    DELETE ctable_in.vname, ctable_in.longname, ctable_in.section, ctable_in.level, ctable_in.cnum, ctable_in.cmax, ctable_in.ctext, ctable_in.check2, ctable_in.vnameorig, ctable_in.match, cfreqs_in.vname
    FROM ctable_in LEFT JOIN cfreqs_in ON (ctable_in.[vname] = cfreqs_in.[vname]) AND (ctable_in.[cnum] = cfreqs_in.[cnum])
    WHERE (((ctable_in.section)="h") AND ((ctable_in.ctext) Like "*break*") AND ((cfreqs_in.vname) Is Null))

    Basically, I am trying to delete the records in ctable_in that don't have a matching record in cfreqs_in based on the criteria specified in the where statement.

    Any suggestions to make this run successfully would be appreciated.



    Thanks.



  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Try DELETE DISTINCTROW .....
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    SEMich is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    4
    Hi isladogs,

    I tried this and it still got the same message:

    DELETE DISTINCTROW ctable_in.vname, ctable_in.longname, ctable_in.section, ctable_in.level, ctable_in.cnum, ctable_in.cmax, ctable_in.ctext, ctable_in.check2, ctable_in.vnameorig, ctable_in.match, cfreqs_in.vname
    FROM ctable_in LEFT JOIN cfreqs_in ON (ctable_in.[vname] = cfreqs_in.[vname]) AND (ctable_in.[cnum] = cfreqs_in.[cnum])
    WHERE (((ctable_in.section)="h") AND ((ctable_in.ctext) Like "*break*") AND ((cfreqs_in.vname) Is Null));

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Probably not the problem, but just in case, LEVEL is an MSACCESS reserved word.

  5. #5
    SEMich is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    4
    Thanks, davegri. No luck with removing it from the text.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by SEMich View Post
    I would like to delete records that are in one table but not the other, ...
    <snip>Basically, I am trying to delete the records in ctable_in that don't have a matching record in cfreqs_in based on the criteria specified in the where statement.
    <snip>
    I was going to suggest changing the "DELETE DISTINCTROW? to "SELECT" to see if any records are selected/returned, but when I reformatted the SQL I got
    Click image for larger version. 

Name:	DeleteSQL1.png 
Views:	13 
Size:	72.7 KB 
ID:	45993



    I would try deleting ", cfreqs_in.vname" from the field list - like this
    Code:
    DELETE DISTINCTROW ctable_in.vname, ctable_in.longname, ctable_in.section, ctable_in.level, ctable_in.cnum, ctable_in.cmax, ctable_in.ctext, ctable_in.check2, ctable_in.vnameorig, ctable_in.match
    FROM ctable_in LEFT JOIN cfreqs_in ON (ctable_in.[vname] = cfreqs_in.[vname]) AND (ctable_in.[cnum] = cfreqs_in.[cnum])
    WHERE (((ctable_in.section)="h") AND ((ctable_in.ctext) Like "*break*") AND ((cfreqs_in.vname) Is Null));

  7. #7
    SEMich is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    4
    Thanks, ssanfu! That did the trick! Stupid me.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help - I've done the same and worse...

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

Similar Threads

  1. Replies: 4
    Last Post: 09-03-2019, 09:09 AM
  2. Replies: 1
    Last Post: 02-06-2018, 11:13 AM
  3. Delete Query for Tables with Relationships
    By mgilbert86 in forum Queries
    Replies: 1
    Last Post: 10-19-2016, 10:06 AM
  4. Query to delete across tables
    By Gauchey in forum Queries
    Replies: 7
    Last Post: 07-17-2015, 12:49 PM
  5. Replies: 3
    Last Post: 07-16-2010, 12:32 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