Example: UPDATE With a Noncorrelated Subquery in its WHERE Clause - Teradata Vantage - Analytics Database

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-04-02
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantage™

The following UPDATE operation uses a subquery to decrease the list price on an electroacoustic CD budget line for labels containing the string ‘erstwhile’:

     UPDATE disc
     SET price = price * .85
     WHERE label_no IN (SELECT label_no
                        FROM label
                        WHERE label_name LIKE '%erstwhile%')
                        AND   line = 'NEA';

You can obtain the same result by writing the query using a join between the disc and label tables on label_no:

     UPDATE disc
     SET price = price * .85
     WHERE disc.label_no = label.label_no
     AND   label_name LIKE '%erstwhile%'
     AND   line = 'NEA';