tab1和tab2中有几个相同的字段,例如userid,name,age,现在要将tab1中的name,age更新到tab2中相同userid的name,age字段中,请问sql语句该怎样写?
解决方案 »
- mysql 的奇怪问题
- mysql-noinstall-5.0.27-win32可不可以把整个目录copy到其它机上运行?
- 一对多联合查询效率问题?
- 为什么通过网络访问MYSQL特别慢,而在MYSQL服务器上访问就很快(不是带宽问题,MSSQL就没问题)
- mysql select语句变慢
- 这条sql语句执行起来非常慢,求大神指点一下
- mysql数据库利用主从同步部署为环形互相热备的方案
- winxp下安装mysql5.7提示mysqld.exe不是有效的win32文件
- 请教高手:随机打乱数据库某个字段的所有值的sql语句写法
- mysql8.0 正确的密码却无法登录
- MYSQL占用内存过多?
- where 的条件用 && 连接时 不能后接order by 不知道是怎么回事?
技术不好,写的很复杂
[code=SQL]update `tab2` set name=(select name from tab1 where tab2.userid=tab1.userid),age=(select age from tab1 where tab2.userid=tab1.userid) where tab2.userid in (select userid from tab1);[code]
set name=tab1.name,age=tab1.age
from tab2,tab1
where tab2.userid=tab1.userid
update tab1,tab2 set tab2.name = tab1.name, tab2.age = tab1.age where tab1.userid = tab2.userid;
update tab2
set name=tab1.name,age=tab1.age
from tab2,tab1
where tab2.userid=tab1.userid
这样的方法可以么? (在SQLServer中是这样的)
set tab2.name = tab1.name, tab2.age = tab1.age