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.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
vjt1596846980081.ditamap
dita:ditavalPath
vjt1596846980081.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.