2023年8月3日发(作者:)
sql批量更新update嵌套select更新概述有两张表【user】和【city】,user表的
city_uuid、city_no 和 city 表的
city_uuid、city_no ⼀⼀对应,但是 user 表只有city_uuid,这时候需要将 city 对应的
city_no 批量更新到 user 表中批量更新⽅式第⼀种⽅式(inner join 内连接)update uset _no = _nofrom user u
inner join city c
on _uuid = _uuidwhere _uuid is not null and _no is null第⼆种⽅式(⼦查询)update uset _no = (select _no from city c where _uuid = _uuid)from user u第三种⽅式:(笛卡尔积)update uset _no = _no
from [user] u, city c
where _uuid = _uuidupdate 多表更新update table1 t1,table2 t2, table3 t3, ... , tablen tnset = ?, , = ?, ... , = ?where = ?, = ?, ... , = ?案例:(conditionUuid是user表的外键,每个conditionUuid对应两条user记录,将producter记录覆盖consumer记录的指定字段值)update r2set id = id, me = me , = , dTime = '2021-02-22 22:22:22.222'from user r1inner join user r2on ionUuid = ionUuidwhere ionValue = 'condition-consumer-00000' and me is not nulland ionValue = 'condition-producter-0000' and me is not null
2023年8月3日发(作者:)
sql批量更新update嵌套select更新概述有两张表【user】和【city】,user表的
city_uuid、city_no 和 city 表的
city_uuid、city_no ⼀⼀对应,但是 user 表只有city_uuid,这时候需要将 city 对应的
city_no 批量更新到 user 表中批量更新⽅式第⼀种⽅式(inner join 内连接)update uset _no = _nofrom user u
inner join city c
on _uuid = _uuidwhere _uuid is not null and _no is null第⼆种⽅式(⼦查询)update uset _no = (select _no from city c where _uuid = _uuid)from user u第三种⽅式:(笛卡尔积)update uset _no = _no
from [user] u, city c
where _uuid = _uuidupdate 多表更新update table1 t1,table2 t2, table3 t3, ... , tablen tnset = ?, , = ?, ... , = ?where = ?, = ?, ... , = ?案例:(conditionUuid是user表的外键,每个conditionUuid对应两条user记录,将producter记录覆盖consumer记录的指定字段值)update r2set id = id, me = me , = , dTime = '2021-02-22 22:22:22.222'from user r1inner join user r2on ionUuid = ionUuidwhere ionValue = 'condition-consumer-00000' and me is not nulland ionValue = 'condition-producter-0000' and me is not null
发布评论