Click here to Skip to main content
12,634,982 members (30,924 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL Access
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 18-Sep-12 8:14am
Comments
digimanus 18-Sep-12 15:09pm
   
why not an inner join? Have you tried Cross Join?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If you would like to get purchased items which are not sold, use this query:
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:
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
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100