How can I efficiently update the table based on values from a join table
only when ID – identifier I use to join both of the tables matches perfectly
1 to 1. I mean when joined table has only one ID to the updated table?
DECLARE @T1 TABLE (
ID INT,
NAME VARCHAR(10),
Age int
)
INSERT INTO @T1 VALUES (1, 'Name', null)
DECLARE @T2 TABLE (
ID INT,
Age int
)
INSERT INTO @T2 VALUES (1, 28)
INSERT INTO @T2 VALUES (1, 29)
INSERT INTO @T2 VALUES (1, 30)
In this example table T2 has three records of the ID = 1 which corresponds to one ID
in T1.
And I would like to update T1 only when in T2 there is one record of ID = 1.
(I would like to avoid joining twice table t2 to solve this task …)
Thanks!
1 Answer