Teradata - Update with Joins to Another Table

Raymond Raymond event 2020-12-13 visibility 7,000
more_vert

In SQL Server, JOIN can be used to update target table with values from a joined table. In Teradata, this syntax is not as simple or intuitive as SQL Server. 

Update with a JOIN

The following example updates table test_table1 with data from test_table2.

Database TestDb;
UPDATE test_table1
FROM test_table2 AS SRC
SET amount = amount * SRC.multiplier
WHERE test_table1.category = SRC.category
AND test_table1.amount > 100
AND SRC.is_deleted = 0;

Update with a corelated subquery

This examples shows how to update a table with a corelated subquery.

Database TestDb;
UPDATE test_table1 AS TGT
SET amount = (SELECT amount FROM test_table2 AS SRC WHERE TGT.category = SRC.category)
WHERE TGT.amount > 100;
More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts