Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table 1
Purchased_Items

Contains :
Item_ID:Number
Item_Quantity:Number

Table 2
Sold_Items

Contains :
Item_ID:Number
Item_Quantity:Number

How can I make a summation between two tables in (Item_Quantity), without inner join , these is a case should be handled if an item located in table 1 but not in table 2 , the is a value should be shown and vice versa , which is in table 1

Please help .
Posted
Comments
Herman<T>.Instance 18-Sep-12 15:09pm    
why not an inner join? Have you tried Cross Join?

1 solution

If you would like to get purchased items which are not sold, use this query:
SQL
SELECT *
FROM Purchased_Items
WHERE NOT Item_ID IN (SELECT Item_ID FROM Sold_Items)


If you would like to sum Item_Quantity for both tables:
SQL
SELECT 'Sum Of Purchased_Items' As [Item Description], SUM(Item_Quantity) AS [Item Value]
FROM Purchased_tems
UNION ALL
SELECT 'Sum Of Sold_Items' As [Item Description], SUM(Item_Quantity) AS [Item Value]
FROM Purchased_tems

Example output:

Item DescriptionItem Value
Sum Of Purchased_Items5,000.00
Sum Of Sold_Items2,000.00
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900