TonyScarpelli
Programmer
Below are two SELECT statements.
Can anyone tell me why a JOIN in the second statement is better/faster or whatever than the first statement?
In other words, why use a JOIN?
SELECT Pur_head.PurDate, Pur_head.PONum, Pur_head.company as Vendor, Pur_head.ChargeBack, Pur_item.Descrip, Pur_item.OrderQty as Qty, Pur_item.Cost, (Pur_item.OrderQty * Pur_item.Cost) as Subtotal
FROM Pur_head, Pur_item
WHERE Pur_item.ReqID = Pur_head.ReqID
AND Pur_head.ChargeBack = 1
AND Pur_head.PurDate BETWEEN @StartDate AND @EndDate
ORDER BY Pur_head.PurDate, Pur_head.PONum
SELECT H.PurDate, H.PONum, H.company as Vendor, H.ChargeBack, I.Descrip, I.OrderQty as Qty, I.Cost, (I.OrderQty * I.Cost) as Subtotal
FROM Pur_head H INNER JOIN Pur_item I
ON I.ReqID = H.ReqID
AND H.ChargeBack = 1
AND H.PurDate BETWEEN @StartDate AND @EndDate
ORDER BY H.PurDate, H.PONum
Thanks.
Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102
Can anyone tell me why a JOIN in the second statement is better/faster or whatever than the first statement?
In other words, why use a JOIN?
SELECT Pur_head.PurDate, Pur_head.PONum, Pur_head.company as Vendor, Pur_head.ChargeBack, Pur_item.Descrip, Pur_item.OrderQty as Qty, Pur_item.Cost, (Pur_item.OrderQty * Pur_item.Cost) as Subtotal
FROM Pur_head, Pur_item
WHERE Pur_item.ReqID = Pur_head.ReqID
AND Pur_head.ChargeBack = 1
AND Pur_head.PurDate BETWEEN @StartDate AND @EndDate
ORDER BY Pur_head.PurDate, Pur_head.PONum
SELECT H.PurDate, H.PONum, H.company as Vendor, H.ChargeBack, I.Descrip, I.OrderQty as Qty, I.Cost, (I.OrderQty * I.Cost) as Subtotal
FROM Pur_head H INNER JOIN Pur_item I
ON I.ReqID = H.ReqID
AND H.ChargeBack = 1
AND H.PurDate BETWEEN @StartDate AND @EndDate
ORDER BY H.PurDate, H.PONum
Thanks.
Tony Scarpelli
Clinical Engineering Dept.
Maine Medical Center
Portland, Maine 04102