Hi Tom,
I have a table (T1) and a view is created upon T1 by masking few PI information say (V1)
T1
area_code integer (100 USA, 200 UK)
id integer
Name string
age integer
DOB date
type string (Individual/Company)
V1 (Masked version of T1)
area_code integer (100 USA, 200 UK)
id integer
Name string
age integer
DOB date
type string (Individual/Company)
Now i have a staging table (ST1) which has the id matching with that of T1 and type (Individual/Company). Based on the matching ids between ST1 and T1 i need to update the type in T1 table for all UK Employer/Employees
Below is the update statement i have written
update T1 set type = b.type
from V1 a inner join ST1 b
on a.id = b.id
where a.area_code = 200
When i ran the above query, the type is updated for the entire table T1 that too with a single value 'Individual'. Can you please explain what might have exactly happened.
Thanks
Raj
An update-only merge is probably the way to go here:
create table t (
c1 int primary key,
c2 int
);
create table t_stage (
c1 int primary key,
c2 int
);
insert into t values ( 1, 0 );
insert into t_stage values ( 1, 9999 );
commit;
select * from t;
C1 C2
1 0
merge into t
using t_stage ts
on ( t.c1 = ts.c1 )
when matched then update
set t.c2 = ts.c2;
select * from t;
C1 C2
1 9999
Learn more about it in this video: