Click here to Skip to main content
Rate this: bad
good
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
besthms767
Comments
digimanus at 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
0 Sergey Alexandrovich Kryukov 7,442
1 OriginalGriff 5,996
2 Peter Leow 4,292
3 CHill60 2,858
4 Mika Wendelius 2,850


Advertise | Privacy | Mobile
Web03 | 2.8.150224.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2015
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