如何删除 table 中不存在于 sqlite 中其他 table 中的行

How to delete a row in table which is not present in other table in sqlite

约束是:

  1. Table 有复合 Fks。
  2. 两个 table 在结构上完全相同。

我试过以下方法

查询: delete from fruit where fruit.name and fruit.pos in (select * from fruit except select * from fruit_temp)

结果:

only a single result allowed for a SELECT that is part of an expression: delete from fruit where fruit.name and fruit.pos in (select * from fruit except select * from fruit_temp)

我需要在 table 水果中执行删除操作,其中的行不在 fruit_temp。

在 SQLite 中,IN 仅适用于单个列。

要检查多列,您需要 correlated subquery:

DELETE FROM fruit
WHERE NOT EXISTS (SELECT 1
                  FROM fruit_temp
                  WHERE fruit_temp.name = fruit.name
                    AND fruit_temp.pos  = fruit.pos );