update (
select oo.user_id, uu.user_id uu_id
from operators oo
join
users uu on uu.name = oo.op_name
)
set user_id = uu_id
Вот полный тестовый скрипт (я использую my_users
и my_operators
, чтобы не связываться с вашими данными).
drop table my_users;
create table my_users (
user_id number(2),
name varchar2(30) unique
)
;
insert into my_users (user_id, name)
select 34, 'Billy' from dual union all
select 43, 'Jimmy' from dual union all
select 50, 'Joe' from dual
;
drop table my_operators;
create table my_operators (
op_id number(2),
op_name varchar2(30) unique,
user_id number(2)
)
;
insert into my_operators (op_id, op_name, user_id)
select 12, 'Billy', 35 from dual union all
select 35, 'Jimmy', 46 from dual union all
select 33, 'Joe', 99 from dual
;
update (
select oo.user_id, uu.user_id uu_id
from my_operators oo
join
my_users uu on uu.name = oo.op_name
)
set user_id = uu_id
;
select * from my_operators;