20 Oct 18 · victor ·       Add to Favorites   Report

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

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied