17.05 - Example: UPDATE With a Correlated Subquery in its WHERE Clause - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1146-175K
Language
English (United States)

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.