我尝试删除一些数据,这是我的表的模型:
--------------------
| TABLE1 |
--------------------
| idnode |idattribute|
|____________________|
|6414224 | 109 |
|6912048 | 74 |
|5632108 | 109 |
|5097234 | 109 |
|9874625 | 9 |
--------------------
| TABLE2 |
--------------------
| idnode | value |
|____________________|
|6414224 | BLABLA |
|6414224 | BLA |
|6414224 | BL |
|5097234 | 14524 |
|5097234 | hihi |
我需要在表2中删除所有'idnode',它们在表1中有'idattribute'= 109。
所以,这是我的查询,但它不起作用:
DELETE FROM table2 WHERE idnode IN
(SELECT TAB1.idnode FROM TABLE2 as TAB2, TABLE1 as TAB1 where TAB2.idnode = TAB1.idnode and TAB1.idattribute = 109)
我收到此错误:您无法在FROM子句
中为更新指定目标表'TABLE2'有你的想法吗?
答案 0 :(得分:0)
DELETE FROM table2 WHERE idnode IN
(SELECT idnode FROM TABLE1 WHERE idattribute = 109)
这个怎么样?
答案 1 :(得分:0)
DELETE table2
FROM table1 JOIN table2 USING (idnode)
WHERE table1.idattribute = 109
将是另一种选择。