update
 tbl1
set
  clm1 = :clm1
  ,clm2 = :clm2
where 
  tbl1.k1 = tbl2.clmx
and tbl1.k2 = tbl2.clmy 
and tbl2.ka = :ka
and tbl2.kb = :kb要更新tbl1的clm1和clm2,
k1和k2是tbl1的主键,
ka和kb是tbl2的主键
这么写为什么题是错误阿?

解决方案 »

  1.   

    这当然会错
    应该这样
    update 
    tbl1 
    set 
      clm1 = :clm1 
      ,clm2 = :clm2 
    where 
      exist(select 1 from tbl2 tbl1.k1 = tbl2.clmx 
    and tbl1.k2 = tbl2.clmy 
    and tbl2.ka = :ka 
    and tbl2.kb = :kb)
      

  2.   

    改一下,用INupdate tbl1 
    set  clm1 = :clm1  ,clm2 = :clm2 
    where (k1, k2) 
       IN (select clmx, clmy 
             from tbl2 
            where ka=:ka and kb=:kb);
      

  3.   

    或者直接
    update tbl1
    set 
      clm1 = :clm1 
      ,clm2 = :clm2 
    where (k1,k2) in (select clmx,clmy from tbl2 where ka=:ka and kb=:kb)
      

  4.   

    5楼的办法做了SQL优化,比较好