Example: UPDATE With a Correlated Subquery in its WHERE Clause - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.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.