用in进行多表连接删除操作解决方案
用in进行多表连接删除操作
我想删除系统里面的一些数据,SQL语句:
delete from mom_moallocate where cinvcode in (select cinvcode from inventory where cinvdefine3='*' and issqty=0 )
解释:
mom_moallocate和inventory 为表名
cinvdefine3='*' and issqty=0为删除条件
现在我想加入第3张表mom_orderdetail,多加一个删除条件“status=3”,status只有在mom_orderdetail才有
mom_moallocate和mom_orderdetail相关联的字段为modid
mom_moallocate和inventory相关联的字段为cinvcode(大家都懂的)
请问这样的SQL语句怎样写?最好还是用in。
------解决方案--------------------
我想删除系统里面的一些数据,SQL语句:
delete from mom_moallocate where cinvcode in (select cinvcode from inventory where cinvdefine3='*' and issqty=0 )
解释:
mom_moallocate和inventory 为表名
cinvdefine3='*' and issqty=0为删除条件
现在我想加入第3张表mom_orderdetail,多加一个删除条件“status=3”,status只有在mom_orderdetail才有
mom_moallocate和mom_orderdetail相关联的字段为modid
mom_moallocate和inventory相关联的字段为cinvcode(大家都懂的)
请问这样的SQL语句怎样写?最好还是用in。
------解决方案--------------------
- SQL code
delete A from mom_moallocate A inner join mom_orderdetail B on A.modid = B.modid where B.[status]=3 and A.cinvcode in ( select cinvcode from inventory where cinvdefine3='*' and issqty=0 )