I have a table table1
o_id
as PK
, ipaddress
, b_id
o_id ip b_id
9205 10.10.10.10 null
9206 10.10.10.11 null
9207 10.10.10.12 null
---more than 1000 rows
I have another table table2
id
as PK
, ipaddress
, b_id
id ip o_id
18356 10.10.10.10 null
18357 10.10.10.11 null
18358 10.10.10.12 null
---more than 1000 rows
Now, if ipaddress
matches in both tables, then I want to update both tables such that table2.o_id = table1.o_id
and table1.b_id = table2.id
update table1
set b_id = table2.id
where ip = table2.ip
Here I want to update o_id
in second table from the o_id
in first table.
I also want to update b_id
in first table from id
in second table.
Is above query correct? there a way to update both tables in single query?