10条数据,通过SQL语句保留id为2和7的,其他都删除,怎么实现?

2024-11-09 10:34:03
推荐回答(2个)
回答1:

你如果需要连表删除 ,必须先删除 子表 ,
delete from childTable a,parentTable b

where a. fk= b.id and b.id not in ('2','7');

然后再删除 父表
delete from table
where id not in ('2','7')

回答2:

delete from table
where id not in ('2','7')