--批量更新
--1.使用merge into:高效
merge into sys_userdept su
using sys_dept sd on
(su.col=sd.col)
when matched then
update
set su.deptid=sd.id
--2.,一般的更新,col为两表的连接属性
update sys_userdept su
set deptid = (
select id from sys_dept sd
where su.col=sd.col)
------其他解决方案--------------------
+1 ------其他解决方案-------------------- update sys_userdept a
set deptid = (select id from sys_dept b where a.KEYS=b.KEYS)
update sys_userdept a
set deptid = (select id from sys_dept b where a.KEYS=b.KEYS)
where exists (select id from sys_dept b where a.KEYS=b.KEYS) ------其他解决方案--------------------
--做一下连接查询就可以了
update sys_userdept a
set deptid = (select id from sys_dept b
where a.id=b.id
)
------其他解决方案-------------------- 顶起
------其他解决方案-------------------- update sys_userdept a
set deptid = (select id from (select id from sys_dept group by id) b
where a.id=b.id)
where exists
(select 1 from (select id from sys_dept group by id) b
where a.id=b.id
)
应该是sys_dept表中存在多条记录与sys_userdept 对应 ------其他解决方案-------------------- select id from sys_dept 是不是多条记录了, 更新数据集不是这样写的
where 条件要…………………… ------其他解决方案--------------------