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

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