使用Join和Where子句访问Access删除查询

时间:2017-05-30 16:23:01

标签: sql ms-access

我有2个表( tblTrainingElements tblCourses )。

tblTrainingElements 包含以下字段: ([培训元素ID],[课程ID],[标题],[持续时间(分钟)],[患者],[状态],[描述],[评论],[网站],[ElementSeq])

tblCourses 具有以下相关字段: [课程ID],[App ID]

我需要删除 tblTrainingElements 中的所有记录 tblCourses =" CAD"中的[App ID]。我需要加入[课程ID]字段中的表格。下面是我尝试使用的SQL语句。我一直收到错误消息"请指定您要从"

中删除哪个表
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"))

2 个答案:

答案 0 :(得分:1)

仅在tblTrainingElements表中删除记录:

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

答案 1 :(得分:0)

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