您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

[转]mysql从一个表字段赋值给另一个表字段 搜集

2024/4/24 23:33:20发布3次查看
[转]mysql从一个表字段赋值给另一个表字段 收集 方法一: mysql从一个表字段赋值给另一个表字段,在线等待。 table1 ? 中 ? 有字段 ? id,uid,name table2 ? 中 ? 有字段 ? id,name table1中的uid和table2中的id是一一对应的。 我如何把table2中的name一一对应
[转]mysql从一个表字段赋值给另一个表字段 收集
方法一:
mysql从一个表字段赋值给另一个表字段,在线等待。
table1 ? 中 ? 有字段 ? id,uid,name
table2 ? 中 ? 有字段 ? id,name
table1中的uid和table2中的id是一一对应的。
我如何把table2中的name一一对应赋值给table1中name
我的环境是mysql4.0.18nt+php4
------解决方法--------------------
insert into table1 (uid, name)
select id as uid,
name
from table2;
------解决方法--------------------
update table1,table2 set table1.name = table2.name where table1.uid = table2.id;
?
方法二:
网上的题目写的:有两个表a和b,均有key和value两个字段,如果b的key在a中也有,就把b的value换为a中对应的value这道题的sql语句怎么写?update b set b.value=(select a.value from a where a.key=b.key) where b.id in(select b.id from b,a where b.key=a.key);但是如果没有id字段 这样更新是否可以?update b set b.value=(select a.value from a where a.key=b.key) where b.key in(select b.key from b,a where b.key=a.key);
------解决方法--------------------
没什么问题,但习惯都写成 exists,不用in
------解决方法--------------------
可以的,
还可以用merge,更简洁。
sql codemerge into b using a on (b.key=a.key)when matched then update set b.value=a.value;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录