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

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
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

You can specify a scalar subquery in the same way that you specify a column or constant in the SET clause of an UPDATE request.

The following example specifies a scalar subquery in its SET clause:

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