Example: UPDATE With a Correlated Subquery in its WHERE 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™

For a noncorrelated subquery, change the subquery to include all tables it references in the inner FROM clause.

     UPDATE publisher
     SET pubnum = NULL
     WHERE 0 = (SELECT COUNT(*)
                FROM book, publisher
                WHERE book.pubnum = publisher.pubnum);

The request does not contain a correlated subquery and the condition in the subquery has a local defining reference. The count, determined once, is nonzero, and no rows are deleted.

For additional examples of correlated and noncorrelated subqueries, see Correlated Subqueries.