Example: UPDATE With a Scalar Correlated Subquery in its SET Clause - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
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);