我想删除另一个表示例中没有现有外键的所有行:
table1 +----+-------+ |id | data | +----+-------+ | 1 | hi | +----+-------+ | 2 | hi | +----+-------+ | 3 | hi | +----+-------+ | 4 | hi | +----+-------+ | 5 | hi | +----+-------+ table2 +----+-------+ |a_id| data | +----+-------+ | 1 | hi | +----+-------+ | 20 | hi | +----+-------+ | 3 | hi | +----+-------+ | 40 | hi | +----+-------+ | 5 | hi | +----+-------+
该 查询 将删除表2上ID为20和40的行。
我需要这样做,以便可以与table1和table2建立关系。
DELETE table2 FROM table2 LEFT JOIN table1 ON table2.a_id = table1.id WHERE table1.id IS NULL