0

此查询将删除所有行,而我只想删除measureid两个表中匹配的行,如下所示:

delete from temp1 
where exists (select t1.* 
              from temp1 t1, temp2 t2 
              where t2.measureid = t1.measureid)

我必须改变什么?

4

2 回答 2

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);
于 2012-09-10T21:17:55.150 回答
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)
于 2012-09-10T21:18:21.177 回答