inner join on selected Result sets?? | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

inner join on selected Result sets??

I almost run into this problem whenever i try to write a complex query.. What i essentially want to do is: (select x,y from z) inner join (select a,b from c) on …
Specifying where condition outside inner join doesnt work because some times. i want to do aggregations before i do inner join…
Any Ideas!
Post some sample data and the result you want Madhivanan Failing to plan is Planning to fail
Not sure if this is kind of what you want.
USE Northwind SELECT t1.* FROM [order details] t1 INNER JOIN
(SELECT orderid, MAX(Quantity) AS Max_Quantity FROM [order details] GROUP BY orderid) t2
ON t1.orderid = t2.orderid
AND t1.Quantity = t2.Max_Quantity
WHERE t1.OrderID BETWEEN 10248 AND 10260
ORDER BY t1.orderid

Frank Kalis
Microsoft SQL Server MVP
Heute schon gebloggt?
Hi Frank, thanks for the information!
That is what i am looking for..