从链接表中删除不存在的记录

时间:2015-01-18 06:57:26

标签: sql sqlite

我已经获得了这个SQL代码,可以很好地将主表(Project Tracker)中的记录添加到详细信息表(Week01)。

insert into Week01 (UserName, RecNum)
select "JustMe", p.RecNum
from `Project List` p
left join Week01 w on p.RecNum = w.RecNum and w.userName = "JustMe"
where w.RecNum is NULL

现在我需要做相反的事情。如果在项目跟踪器中不存在Week01中的RecNums,我想删除Week01中的行。

1 个答案:

答案 0 :(得分:1)

DELETE FROM Week01
WHERE RecNum NOT IN (SELECT RecNum
                     FROM [Project List])