------解决方案-------------------- delete from a from a left join b on a.id=b.aid where b.aid is null;
------解决方案-------------------- delete from a where id not in(select a.id from a,b where a.id=b.aid);
------解决方案-------------------- delete a from a from a left join b on a.id=b.aid where b.aid is null;
一楼少写了个 a
------解决方案--------------------
SQL code
delete a from a left join b on a.id=b.aid where b.aid is null;
------解决方案-------------------- 是不是因为id没指明是a表的,应该是delete from a where a.id not in(select a.id from a,b where a.id=b.aid);
------解决方案-------------------- delete from a where not exists(select 1 from b where a.id=aid);
------解决方案--------------------
SQL code
create table a(id int);
create table b (aid int);
insert a values (1),(2),(3);
insert b values(1);
delete from a where not exists(select 1 from b where a.id=aid);
select * from a
+------+
| id |
+------+
| 1 |
+------+
------解决方案--------------------
------解决方案--------------------
------解决方案-------------------- where isnull(b.aid) 是不是这样的?