Example: UPDATE With a Scalar Correlated Subquery in its SET Clause - Advanced SQL Engine - Teradata Database

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

When a scalar correlated subquery is specified in the SET clause, even if the UPDATE request does not have a FROM clause, the database treats the update as a joined update because of the scalar correlated subquery.

The following example requires sales_sum_table to be joined with salestable, and the update is done using a merge update operation via a spool.

     UPDATE sales_sum_table AS sst
     SET  total_sales = (SELECT SUM(amount) 
                         FROM sales_table AS s
                         WHERE s.day_of_sale BETWEEN sst.period_start 
                                             AND     sst.period_end);