日期:2014-05-16  浏览次数:20792 次

在MySql中如何将一张表的内容更新到另一张表中?
现在有两张表t_soft1,t_soft2,这两张表有两个相同名称的列id,softlinks,其中id为主键并且两张表的id列数据完全相同。我现在想把t_soft2的softlinks列的数据覆盖t_soft1的数据。在MSSql我用下面的语句成功实现,但在MySql环境中用PhpAdmin就报错,请问是什么原因?
update t_soft1 set softlinks = t_soft2.softlinks from t_soft1,t_soft2 where t_soft1.id = t_soft2.id

------解决方案--------------------
update t_soft1,t_soft2 where t_soft1.id = t_soft2.id
set t_soft1.softlinks = t_soft2.softlinks
------解决方案--------------------
update t_soft1 set softlinks = t_soft2.softlinks from t_soft1,t_soft2 where t_soft1.id = t_soft2.id

这个MSSQL的写法,是在mysql里不支持的,改成如下:

update t_soft1 inner join t_soft2 on t_soft1.id = t_soft2.id
set t_soft1.softlinks = t_soft2.softlinks 



update t_soft1,t_soft2 set t_soft1.softlinks = t_soft2.softlinks 
where t_soft1.id = t_soft2.id