Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 union

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-04-11 : 11:03:00
i have tableA where already did the total count with the country:

tableA:
ID TotalSold Blue Red Code
1 10 5 5 ABC
2 3 2 1
3 40 30 10
4 15 5 10 DEF

i have another tableB which store the total amount of COde:

tableB:
Code Total
ABC USD89
DEF USD90

But when i try to inner join the code the total Sold will only appear with the code as below:

ID TotalSold Blue Red Code Total
1 10 5 5 ABC USD89
4 15 5 10 DEF USD90

How can i appear all as below:?

ID TotalSold Blue Red Code Total
1 10 5 5 ABC USD89
2 3 2 1
3 40 30 10
4 15 5 10 DEF USD90

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-11 : 11:20:14
Do a LEFT JOIN instead of INNER JOIN with the tableA on the left side (first table) and tableB on the right side (second table)
select a.*,b.Total
from TableA a left join TableB b on
a.Code=b.Code
Go to Top of Page
   

- Advertisement -