In this code we're asking for minimal price for product of particular supplier but I' don't understand why we have to set an alias for the outer query.
QUERY 1: - Returns any records where UnitPrice is the smallest.
SELECT SupplierID
,ProductName
,UnitPrice
FROM Products
WHERE UnitPrice = (
SELECT MIN(UnitPrice)
FROM Products
WHERE SupplierID = Products.SupplierID
)
QUERY 2: - Returns records with the lowest price for each supplier.
SELECT SupplierID
,ProductName
,UnitPrice
FROM Products AS p1
WHERE UnitPrice = (
SELECT MIN(UnitPrice)
FROM Products
WHERE SupplierID = p1.SupplierID
)
Is this code recursive ?
I'm using the Northwind sample database.