UPDATE from another table in Snowflake

The update command can be used to update specified rows in the target table with new values. If you have moved from Teradata, note that in Teradata we have the "from" clause first followed by "set".

Example:
update t1
set t1.number_column = t1.number_column + t2.number_column, t1.text_column = 'ASDF'
from t2
where t1.key_column = t2.t1_key and t1.number_column < 10;

Or you can even do a derived table, like the below,

update target set v = b.v
from (select k, min(v) v from src group by k) b
where target.k = b.k;

Syntax:

UPDATE <target_table>
SET <col_name> = <value> [ , <col_name> = <value> , ... ]
[ FROM <additional_tables> ]
[ WHERE <condition> ]

victor

posted on 20 Oct 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds