我想从Table2中删除我的行,其中ID存在于Table1中,而在Table1中,确定是否应该发生删除的值存在.
例:
表格1
+--------+--------+
| ID | Author |
+--------+--------+
| 121 | John |
+--------+--------+
| 150 | Ann |
+--------+--------+
Run Code Online (Sandbox Code Playgroud)
表2
+--------+---------+-----------+
| ID | MetaKey | MetaValue |
+--------+---------+-----------+
| 121 | Color | red |
+--------+---------+-----------+
| 150 | Color | grey |
+--------+---------+-----------+
| 121 | Weight | 10 |
+--------+---------+-----------+
| 150 | Weight | 30 |
+--------+---------+-----------+
Run Code Online (Sandbox Code Playgroud)
并删除Table2中的行,其作者是'John'(来自Table1)
您可以使用exists子句和相关子查询来执行此操作:
delete from t2
where exists (select 1 from t1 where t2.id = t1.id and t1.Author = 'John')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
181 次 |
| 最近记录: |