I wondered if someone could explain something to me, I am trying to teach myself T-SQL from a book, and I have just done a couple of exercises, the first one is wrong and the second is correct (ran against the Adventureworks DB), although both have the same tables involved, I cant work out what makes the second one correct, or to put it another way, why the results are not the same. I'd really appreciate some explanation, I cant work it out. I think it might be the order of the joins?
----2 I got this wrong, I cant work out how though
--select sum(OrderQty) as SumOfOrderQTY, p.ProductID, soh.OrderDate
--from Production.Product as p
--inner join sales.salesorderdetail as SOD
--on p.ProductID = sod.ProductID
--inner join sales.salesorderheader as SOH on soh.salesorderid = sod.SalesOrderID
--group by p.productid, soh.OrderDate;
----2 This is the correct one solution.
--select sum(orderqty) SumOfOrderQty, p.productid, soh.orderdate
--from sales.salesorderheader as soh
--inner join sales.salesorderdetail as sod
--on soh.salesorderid = sod.salesorderdetailid
--inner join production.product as p on sod.productid = p.productid
--group by p.productid, soh.orderdat
Thanks in advance for ANY help.