简体   繁体   中英

Ms Access Delete Query with Join and Where Clause

I have 2 tables ( tblTrainingElements and tblCourses ).

tblTrainingElements has the following fields: ([Training Element ID], [Course ID], [Title],[Duration (min)],[Patient],[Status],[Description], [Comments],[Site],[ElementSeq])

tblCourses has the following relevant fields: [Course ID], [App ID]

I need to delete all records in tblTrainingElements WHERE the [App ID] from tblCourses = "CAD". I need to join the tables on the [Course ID] field. Below is the SQL statement that I tried to use. I keep getting the error message "Please specify which table you would like to delete from"

DELETE tblCourses.[Course Name], tblCourses.[App ID], tblTrainingElements.[Training Element ID], tblTrainingElements.[Course ID], tblTrainingElements.Title, tblTrainingElements.[Duration (min)], tblTrainingElements.Patient, tblTrainingElements.Status, tblTrainingElements.Description, tblTrainingElements.Comments, tblTrainingElements.Site, tblTrainingElements.ElementSeq

FROM tblCourses INNER JOIN tblTrainingElements ON tblCourses.[Course ID] = tblTrainingElements.[Course ID]

WHERE (((tblCourses.[App ID])="CAD"))

Delete records only in tblTrainingElements table:

DELETE *
FROM tblTrainingElements
WHERE tblTrainingElements.[Course ID] IN (SELECT tblCourses.[Course ID] FROM tblCourses WHERE tblCourses.[App ID]="CAD" );
DELETE tc
FROM tblCourses tc 
INNER JOIN tblTrainingElements tte ON tc.[Course ID] = tte.[Course ID]
WHERE (((tc.[App ID])="CAD"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM