表a
id name
1 a
2 b
3 c
4 d
表b
id a_id
1 1
2 3
-----------
期望结果
2 b
4 d
-----------
实际上b表中的a_id是和a表中的id对应。
sql: select * from a where id not in (select a.id from a join b on a.id=a_id);
有简单点的写法吗?
id name
1 a
2 b
3 c
4 d
表b
id a_id
1 1
2 3
-----------
期望结果
2 b
4 d
-----------
实际上b表中的a_id是和a表中的id对应。
sql: select * from a where id not in (select a.id from a join b on a.id=a_id);
有简单点的写法吗?
select * from a where id not in (
select a_id from b
)
from a
where not exists (select 1 from b where id=a.id)