S
Smartin
Good Day All,
I will use the Northwind table "Order Details" as an example for what I
am trying to do.
I would like to obtain, for each order, the product ID which has the
highest unit cost.
I tried the simplest approach:
SELECT
[Order Details].OrderID,
First([Order Details].ProductID) AS FirstOfProductID,
Max([Order Details].UnitPrice) AS MaxOfUnitPrice
FROM
[Order Details]
GROUP BY [Order Details].OrderID;
This clearly doesn't work. It does return MAX(UnitPrice) correctly, but
does not always return the corresponding ProductID which has that price
(e.g. see the result for OrderID 10253).
I'm not concerned about ties where two products have the same price as
in my real life problem this does not matter.
If anyone as SQL 101 pointers for me I would be much appreciative.
I will use the Northwind table "Order Details" as an example for what I
am trying to do.
I would like to obtain, for each order, the product ID which has the
highest unit cost.
I tried the simplest approach:
SELECT
[Order Details].OrderID,
First([Order Details].ProductID) AS FirstOfProductID,
Max([Order Details].UnitPrice) AS MaxOfUnitPrice
FROM
[Order Details]
GROUP BY [Order Details].OrderID;
This clearly doesn't work. It does return MAX(UnitPrice) correctly, but
does not always return the corresponding ProductID which has that price
(e.g. see the result for OrderID 10253).
I'm not concerned about ties where two products have the same price as
in my real life problem this does not matter.
If anyone as SQL 101 pointers for me I would be much appreciative.