0
所有行都得到與此查詢刪除,而我只是想刪除這些行,其中measureid
匹配下面兩個表中:SQL從兩個表中的查詢匹配條件中刪除?
delete from temp1
where exists (select t1.*
from temp1 t1, temp2 t2
where t2.measureid = t1.measureid)
我有什麼改變?
所有行都得到與此查詢刪除,而我只是想刪除這些行,其中measureid
匹配下面兩個表中:SQL從兩個表中的查詢匹配條件中刪除?
delete from temp1
where exists (select t1.*
from temp1 t1, temp2 t2
where t2.measureid = t1.measureid)
我有什麼改變?
我不認爲你想使用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);
這是因爲
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)