循环进入MS Access以删除行

时间:2019-06-24 18:18:46

标签: sql ms-access

我想删除表中包含代码的列中包含某些代码的所有行。 例如:

Name     Code
John     3581
Alex     3132
Jake     2123

在另一个表中,我有对应于某个关键字的代码。其中一些名称具有与我要消除的选择关键字相对应的代码。看起来像这样 例如:

Code    Keyword
3132    apple
2123    apple
4921    banana

比方说,我只想从名称表中筛选出苹果。我该怎么办?

我尝试设置循环,但是我想您无法在MS Access中做到这一点。另外,我想尝试使用WHERE语句。

这就是我的想法

DELETE table1 where table1.numbers = table2.numbers;

我只是不确定如何执行此代码。

2 个答案:

答案 0 :(得分:0)

如果您要从table1中删除Code中具有table2 Keyword的{​​{1}}行,则可以使用{{1 }}:

apple

答案 1 :(得分:0)

您也可以使用in来避免相关子查询:

delete from table1 t1 where t1.code in 
(select t2.code from table2 t2 where t2.keyword = 'apple')

在这里,table1是包含NameCode的表,而table2是包含CodeKeyword的表-更改这些表名称以适合您的数据。