How to delete in MS Access when using JOIN's?

后端 未结 3 1472
渐次进展
渐次进展 2020-12-01 05:24

I am attempting to use the DELETE clause in MS Access and have an issue when also using the JOIN clause. I have notice this can be accomplished by

3条回答
  •  时光说笑
    2020-12-01 06:16

    Delete Table1.*
    From Table1
    Where Exists( Select 1 From Table2 Where Table2.Name = Table1.Name ) = True
    

    To expand on my answer, the official SQL specification does not provide for using Joins in action queries specifically because it can create ambiguous results. Thus, it is better (and Access is much happier) if you can avoid using Joins in action queries like I have here. The reason that Access wants DISTINCTROW is that it is likely that the Join between the two tables would create duplicates of Table1 rows (i.e., there are multiple related rows in Table2) and thus Access gets confused. I've also found that if you try to use a Join and a primary key does not exist Access will balk. In general, it is better to avoid a join in an action query if you can.

提交回复
热议问题