Monday, January 25, 2016

Co-Related Subqueries in TD

Example : SELECT Requests With a Correlated Subquery


The following SELECT request uses a correlated subquery to return the names of the employees who have the highest salary in each department.

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

The following SELECT request uses a correlated subquery to return the names of publishers with no books in the library.

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

No comments:

Post a Comment