Thursday, January 28, 2016

Correlated Subqueries

Correlated subqueries are subqueries where the iner query has a reference to a column from the table in the outer query.


Find out products with the minimum unit price per category.

select categoryid,productid, productname,unitprice
from production.products as p1
where unitprice=
(select min(unitprice)
 from production.products as p2
 where p2.categoryid=p1.categoryid);

No comments:

Post a Comment