当前位置:主页 > 数据库 > Mysql >

MySQL将select结果执行update的实例教程

时间:2022-04-15 09:30:51 | 栏目:Mysql | 点击:

一、单表查询―>更新

UPDATE table_name
SET field1=new-value1, field2=new-value2
[WHERE Clause]

二、多表联合查询―>更新

UPDATE a
INNER JOIN (SELECT yy FROM b) c ON a.id = c.id 
SET a.xx = c.yy
[WHERE Clause]

例子:

tableex_copy1表

tablein_copy1表

查询SQL

SELECT * FROM
tableex_copy1 a LEFT JOIN
(SELECT * FROM tablein_copy1) b
ON a.BID = b.AID
WHERE b.ASEX = '女'

update SQL

UPDATE
#SELECT * FROM
tableex_copy1 a LEFT JOIN
(SELECT * FROM tablein_copy1) b
ON a.BID = b.AID
SET a.CESHI = '6666'
WHERE b.ASEX = '女'

更新之后的tableex_copy1表

总结

您可能感兴趣的文章:

相关文章