SQL Query Help SUM of Columns accross multiple tables

sqlsum

Hi I wonder if you can help with the following query , I am going around in circles trying to get the syntax correct.

I have two Tables Orders

OrderID | Product ID | LineTotal
   1         ABC          2
   2         CDE          3
   2         DEF          1

and Products Table Containing the Weight and Cost

ProductID | Weight | Cost 
   ABC        1        1
   CDE        2        2  
   DEF        1        0.5  

So for each order ID I need to SUM the LineTotal the Weight and the Cost.

Thanks for some pointers on how to go about this as I am getting errors with joins and silly results

Thanks

Best Answer

It should be very simple if I got the task right:

SELECT o.OrderID, o.ProductID, sum = (o.LineTotal + p.Weight + p.Cost) 
FROM ORDERS o
INNER JOIN PRODUCTS p on o.ProductID = p.ProductID