I agree, the second is joining incorrectly on detailid instead of orderid.
In addition, I would through an Order By on both of those queries so the results are easier to compare
ORDER BY p.ProductID,SumofOrderQty;
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events