I have 3 tables:
Table1
-------
ID
Field1
Field2
Table2
_______
ID
Name
Table2_OLD
____________
ID
Name
I need to update ID in table 2 to the ID from Table2 where Table2.Name = Table2_OLD.Name
IDs in Table2 and Table2_OLD are different, only Names are to be used to get the correct ID:
SELECT Table2.ID 
FROM Table2 
  INNER JOIN Table2_OLD ON Table2.Name=Table2_OLD.Name
I wrote the following update statement:
UPDATE Table1 SET Table1.ID=(SELECT DISTINCT t2.ID
                             FROM Table2 t2
                               INNER JOIN Table2_OLD t3 
                                       ON t2.Name=t3.Name 
                                      AND t2.ID=Table1.ID)
but it gives me an error
cannot update Table1.ID to null`
I tried using
UPDATE Table1 SET Table1.ID = (SELECT DISTINCT t2.ID
                               FROM Table2 t2
                                 INNER JOIN Table2_OLD t3 
                                         ON t2.Name=t3.Name 
                                        AND t2.ID=Table1.ID 
                                        AND NOT t2.ID is null)
but got the same error.
Can anyone help?
 
     
    