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

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

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);