I have this two tables
Transactions table
TESTE TABLE
And I want to update the value of column NEW_COLUMN of table Transactions with the value of TESTE column of table TESTE if the value of SourceID is equal to the value of ID. How can I do it?
I have this two tables
And I want to update the value of column NEW_COLUMN of table Transactions with the value of TESTE column of table TESTE if the value of SourceID is equal to the value of ID. How can I do it?
create table Transactions (SourceID int , NEW_COLUMN varchar(64));
insert into Transactions (SourceID, NEW_COLUMN) values 
(1, 'Default'),(2, 'Default'),(3, 'Default');
create table TESTE (ID int , TESTE varchar(64));
insert into TESTE (ID, TESTE) values 
(1, 'TESTE1'),(3, 'TESTE3');
select * from Transactions;
select * from TESTE;
    UPDATE Transactions 
    JOIN(SELECT TESTE, ID
    FROM TESTE) x ON SourceID = ID
    SET NEW_COLUMN = TESTE
    WHERE SourceID = ID;
select * from Transactions order by SourceID;
Table: Transactions
+==========+============+
| SourceID | NEW_COLUMN |
+==========+============+
| 1        | Default    |
+----------+------------+
| 2        | Default    |
+----------+------------+
| 3        | Default    |
+----------+------------+
Table: TESTE    
+====+========+
| ID | TESTE  |
+====+========+
| 1  | TESTE1 |
+----+--------+
| 3  | TESTE3 |
+----+--------+
    
    ✓
Resulting Table: Transactions 
    +==========+============+
    | SourceID | NEW_COLUMN |
    +==========+============+
    | 1        | TESTE1     |
    +----------+------------+
    | 2        | Default    |
    +----------+------------+
    | 3        | TESTE3     |
    +----------+------------+