(在线等)急求一sql语句
两个表a,b
对表b的记录如果id不在表a.id中则删除该记录!!
各位老大指点下.我目前只能想到用not in语句.
[解决办法]
--方法一
Delete From B Where id Not In (Select id From A)
--方法二
Delete From B Where Not Exists (Select id From A Where id = B.id)
--方法三
Delete B From B Left Join A
On A.id = B.id
Where A.id Is Null
[解决办法]
delete b
where id not in(select id from a)
或者
delete b
where not exists(select 1 from a where a.id=b.id)
[解决办法]
用魚兄的方法二,也可以啊