update t_table a    set (f1,f2,f3)=(select f1,f2,f3 from testz b where a.id=b.id)结果a表中id不在b表中的数据也被更新,f1.f2.f3都变成了空值?

解决方案 »

  1.   

    你的sql语句写的不对,应该在where子句中增加限制才对
    update t_table a    set (f1,f2,f3)=(select f1,f2,f3 from testz b )
      where a.id=b.id
      

  2.   


    ...你这个写法明显语法就错误了update t_table a
       set (f1, f2, f3) =
           (select f1, f2, f3 from testz b where a.id = b.id)
     where exists (select 1 from testz b where a.id = b.id)
      

  3.   


    ...你这个写法明显语法就错误了update t_table a
       set (f1, f2, f3) =
           (select f1, f2, f3 from testz b where a.id = b.id)
     where exists (select 1 from testz b where a.id = b.id)
    你的回复是正确的,怎么理解这个事情?
      

  4.   


    ...你这个写法明显语法就错误了update t_table a
       set (f1, f2, f3) =
           (select f1, f2, f3 from testz b where a.id = b.id)
     where exists (select 1 from testz b where a.id = b.id)
    你的回复是正确的,怎么理解这个事情?没有带where条件,那肯定是全表更新了。
     (select f1, f2, f3 from testz b where a.id = b.id)
    这个只是代表能不能更新到值,找不到肯定就会置空。
    跟表需要更新多少数据是没有直接关系的。
      

  5.   

    2楼比1楼好的地方在于"注意空值的影响"
    通常关联update、2楼那样是可以的
      

  6.   

    select f1, f2, f3 from testz b where a.id = b.id这句话有没有返回多行的可能......
      

  7.   

    楼上是对的,要在外层加个where exists的
    update t_table a
       set (f1, f2, f3) =
           (select f1, f2, f3 from testz b where a.id = b.id)
     where exists (select 1 from testz b where a.id = b.id)
      

  8.   

    因为你的(select f1,f2,f3 from testz b where a.id=b.id)这个值为空,为什么为空,因为你条件里只有个b表,而a表在上面,在这里没有写。在from 后面加个“a,”就可以了。
      

  9.   

    当你有多个a.id和b.id相等时就有返回多行了,如果都是唯一就没有了,你注意下你自己条件精确就行了