select * from 主表 a
where not exists(select 1 from 从表 where idm = a.id and quantity <> quantityout)