日期:2014-05-17  浏览次数:20655 次

谁帮我看一下这个简单的sql有什么问题啊
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的主键
这么写为什么题是错误阿?

------解决方案--------------------
提示什么错误?
------解决方案--------------------
tab1和tab2有什么关联吗?
------解决方案--------------------
这当然会错
应该这样
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)
------解决方案--------------------
改一下,用IN

update tbl1 
set clm1 = :clm1 ,clm2 = :clm2 
where (k1, k2) 
IN (select clmx, clmy 
from tbl2 
where ka=:ka and kb=:kb);