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
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

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