求教 主从表 数据剔除

求教 主从表 数据删除现有表 A(主表 字段ID),B(从表ID,A_ID)两张表,现在要删除从表中不被主表关联到的数据

求教 主从表 数据删除
现有表 A(主表 字段ID),B(从表ID,A_ID)两张表,现在要删除从表中不被主表关联到的数据。
不要下面的这种方法
delete from B where B.ID not in( select B.ID from A join B on A.ID = B.A_ID )

[解决办法]

SQL code
delete B where not exists (select 1 from A where A.ID=B.ID)