首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用in进行多表连接删除操作解决方案

2012-06-14 
用in进行多表连接删除操作我想删除系统里面的一些数据,SQL语句:delete from mom_moallocate where cinvcod

用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 Afrom mom_moallocate A    inner join mom_orderdetail B        on A.modid = B.modidwhere B.[status]=3    and A.cinvcode in     (        select cinvcode         from inventory        where cinvdefine3='*'             and issqty=0     ) 

热点排行