Share via

Delete Query with Two Tables

Anonymous
2017-03-15T18:33:08+00:00

I'm trying to delete all the records in the GuardianAndContacts table where no related records exist in the Student_GuardianAndContacts table using the following query, however I get this error message: "Specify the table containing the records you want to delete".  

SELECT GuardiansAndContacts.*, Students_GuardiansAndContacts.ID

FROM GuardiansAndContacts LEFT JOIN Students_GuardiansAndContacts ON GuardiansAndContacts.ID = Students_GuardiansAndContacts.GuardianID

WHERE (((Students_GuardiansAndContacts.ID) Is Null));

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-03-15T19:14:53+00:00

Perhaps something like this:

DELETE * FROM GuardianAndContacts WHERE GuardianID NOT IN (SELECT DISTINCT GuardianID FROM Students_GuardianAndContacts)

That would remove all records from GuardianAndContacts where the GuardianID does not exist in Students_GuardianAndContacts.

Before trying out any Delete processes, be sure to make a backup of your database

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2017-03-16T12:57:23+00:00

    Thanks, worked perfectly.

    Was this answer helpful?

    0 comments No comments