Thanks for reading my post. I'm trying to find the SUM of two colums from two different tables. The tables I'm using are as follows:
Table: Parts
id Name Type
--------------------
1 Screw Quarter
2 Screw Half
3 Nail Half
4 Nail Quarter
Table: Purchases
id Quantity
----------------
1 10
2 10
1 5
3 20
4 7
Table: Sold
id Quantity
-----------------
1 5
2 3
1 5
3 10
1 4
I'm trying to write a SQL statement that will produce the following result:
Name Type Purchase Sold
-------------------------------------------
Screw Quarter 15 14
Screw half 10 3
Nail half 20 10
Nail Quarter 7 0
My SQL statement is not producing the desired table, it is as follows:
SELECT Parts.Name, Parts.Type, SUM(Purchase.Quantity), SUM(Sold.Quantity)
FROM (Parts INNER JOIN Purchases ON Parts.ID = Purchases.ID) INNER JOIN Sold ON Parts.ID = Sold.ID)
GROUP BY Parts.Name, Parts.Type;
Any suggestions would be greatly apprecaited.
Thanks!
Table: Parts
id Name Type
--------------------
1 Screw Quarter
2 Screw Half
3 Nail Half
4 Nail Quarter
Table: Purchases
id Quantity
----------------
1 10
2 10
1 5
3 20
4 7
Table: Sold
id Quantity
-----------------
1 5
2 3
1 5
3 10
1 4
I'm trying to write a SQL statement that will produce the following result:
Name Type Purchase Sold
-------------------------------------------
Screw Quarter 15 14
Screw half 10 3
Nail half 20 10
Nail Quarter 7 0
My SQL statement is not producing the desired table, it is as follows:
SELECT Parts.Name, Parts.Type, SUM(Purchase.Quantity), SUM(Sold.Quantity)
FROM (Parts INNER JOIN Purchases ON Parts.ID = Purchases.ID) INNER JOIN Sold ON Parts.ID = Sold.ID)
GROUP BY Parts.Name, Parts.Type;
Any suggestions would be greatly apprecaited.
Thanks!