用PL/SQL写
现有表1和表2
表1,表2原本都有数据.
要求:把表1中C_DAIMA的数据更新到表2的C_DM里
条件是表1的C_ID要等于表2的C_AID
update t_table2
set c_dm
from t_table1 inner join t_table2 on t_table1.c_id = t_table2.c_aid我用过以上这种方法,不过显示错误,说SQL语句错误,C_DAIMA和C_DM的数据类型是一样的
请问应该怎么改?有什么更好的方法?

解决方案 »

  1.   

    update t_table2 set c_dm=(select c_daima from t_table1 where t_table1.c_id = t_table2.c_aid)
      

  2.   


    补充楼上一下update t_table2 set c_dm=(select c_daima from t_table1 where t_table1.c_id = t_table2.c_aid) where exists(select 1 from t_table1 where t_table1.c_id = t_table2.c_aid);
      

  3.   

    boydgmx(梦霄) 做法才是正確的, sinusoid(黑眼圈) 的沒有加條件,它會將t_table2 表中有而表t_table1中沒有的c_id 值所對應行的c_dm列值全改為空NULL