数据库中有表A 和 表B表A的结构
id       lootid
表B的结构
lid    关系:表A的lootid 对应 表B的  lid要求:检查表A的 lootid 是否在 表B 中存在  如果不存在 则更新表A的lootid为 0怎么写,谢谢

解决方案 »

  1.   

    updte A set lootid=0 where lootid<>0 and lootid not in (select lid from B)
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    update A set lootid=0 where lottid not in(select lid from b)
      

  3.   

    update A set loopid=0 where loopid not in (select lid from B)
      

  4.   

    //也许是这样
    update 表A 
    set lootid = 0
    where (select count(*) from 表B where lid=表A.lootid) <= 0
      

  5.   

    //这样也可以
    update 表A 
    set lootid = 0
    where not exists(select * from a where lid=表A.lootid)
      

  6.   

    都是高手!feiyun0112(http://feiyun0112.cnblogs.com/),zswang(伴水清清)(专家门诊清洁工)得比较好!其他的都不全面!