使用此查询删除所有行,而我只想删除两个表中measureid
匹配的行,如下所示:
delete from temp1
where exists (select t1.*
from temp1 t1, temp2 t2
where t2.measureid = t1.measureid)
我需要改变什么?
答案 0 :(得分:3)
我认为您不想使用exists
我认为您想使用in
delete from temp1 where measureid in
(select t1.measureid from temp1 t1, temp2 t2 where t2.measureid = t1.measureid);
或更好
delete from temp1 where measureid in
(select measureid from temp2);
答案 1 :(得分:1)
那是因为
select t1.* from temp1 t1, temp2 t2 where t2.measureid = t1.measureid
始终返回行。你可能想要的是
delete from temp1 t1 where exists (select t2.* from temp2 t2 where t2.measureid = t1.measureid)