Reputation: 1
I want to update one column in a table, but I want to add a table with join and use a condition in other table. This is my code but it is not correct - can someone help me with this? I am using Oracle dbms
update table_person
inner join table_person_info on table_person.person_id = table_person_info.person_id
set table_person.gender_type_id = 98
where table_person_info.type_id = 51 and table_person.gender_type_id = 97;
Upvotes: 0
Views: 189
Reputation: 1
you should not use inner join but you can use this code if you want to use it
update
(select t1.gender_type_id
from table_person t1 inner join table_person_info t2 on t1.person_id = t2.person_id
where t2.type_id = 51)
set gender_type_id = 98 where gender_type_id = 97
Upvotes: 0
Reputation: 278
First you should build a true table with these two table and then you can update your column
update
(select t1.gender_type_id
from table_person t1 inner join table_person_info t2 on t1.person_id = t2.person_id
where t2.type_id = 51)
set gender_type_id = 98 where gender_type_id = 97
Upvotes: 0
Reputation: 35900
INNER JOIN
in update is not allowed in Oracle. You can use EXISTS
as follows.
update table_person tp
set tp.gender_type_id = 98
where exists
(select 1 from table_person_info tpi where tp.person_id = tpi.person_id
and tpi.type_id = 51)
and tp.gender_type_id = 97;
Upvotes: 3