我想从 Table2 中删除我的行,其中 ID 存在于 Table1 中,并且在 Table1 中存在确定是否应该发生删除的值。
例子:
表1
+--------+--------+
| ID | Author |
+--------+--------+
| 121 | John |
+--------+--------+
| 150 | Ann |
+--------+--------+
表2
+--------+---------+-----------+
| ID | MetaKey | MetaValue |
+--------+---------+-----------+
| 121 | Color | red |
+--------+---------+-----------+
| 150 | Color | grey |
+--------+---------+-----------+
| 121 | Weight | 10 |
+--------+---------+-----------+
| 150 | Weight | 30 |
+--------+---------+-----------+
然后从 Table2 中删除行,作者是 'John'(来自 Table1)
最佳答案
您可以使用 exists
子句和相关子查询来做到这一点:
delete from t2
where exists (select 1 from t1 where t2.id = t1.id and t1.Author = 'John')
关于mysql - 根据另一个表中的信息删除一个表中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18512114/