各位大侠,在线等了,
现在有两个表
Table A (Userid)(1,2,3,4,5) Table B (userid)(1,2,3)
现在想从A中删除Userid不再B中的纪录,即删除掉 4,5
不知道 有没有比较好的写法,由于数据库文件较大,所以 无法用 delete * from A where userid not in (select * from B)
所以 向各位求高效写法!
现在有两个表
Table A (Userid)(1,2,3,4,5) Table B (userid)(1,2,3)
现在想从A中删除Userid不再B中的纪录,即删除掉 4,5
不知道 有没有比较好的写法,由于数据库文件较大,所以 无法用 delete * from A where userid not in (select * from B)
所以 向各位求高效写法!
delete a from A a where not exists(select 1 from B where userid = a.userid)
delete * from A where userid not in (select USERID from B)
from TableA a left join TableB b
on a.userid=b.userid
where b.userid is null
delete a from A a where not exists(select 1 from B where userid = a.userid)这种效率是比较高的