Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

[Help] How to get data of OrderID and the maximum-priced product of each Order

$
0
0

Hi everyone! I have a question:
How to select the orderID, order date and the maximum-price product of each order in the below tables in 2 ways:

1-using correlated sub-query 
2-not using correlated sub-query

I only selected orderID, order date and the maximum price of each order but not including the unit name because it is on the other table and I cannot group it.
This is my query:

SELECT dbo.[Order Details].OrderID, Max(dbo.[Order Details].UnitPrice)as MaxUnitprice, dbo.Orders.OrderDate
FROM  dbo.[Order Details] INNER JOIN
               dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID INNER JOIN
               dbo.Orders ON dbo.[Order Details].OrderID = dbo.Orders.OrderID
GROUP BY dbo.[Order Details].OrderID, dbo.Orders.OrderDate

This is the database:

(Fix link)Database

Please help!



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>