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

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);