Examples: SELECT Statements with a Correlated Subquery - 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™

Use a correlated subquery to return the names of the employees with the highest salary in each department.

     SELECT name
     FROM personnel p
     WHERE salary = (SELECT MAX(salary)
                     FROM personnel sp
                     WHERE p.department=sp.department);

Use a correlated subquery to return the names of publishers without books in the library.

     SELECT pubname
     FROM publisher
     WHERE 0 = (SELECT COUNT(*)
                FROM book
                WHERE book.pubnum=publisher.pubnum);