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.
Author |
Topic |
pinecrest515
Starting Member
11 Posts |
Posted - 2011-01-25 : 13:29:23
|
Dear forumers,I would like to consult urgently on the following:Suppose I have two tables, and want to join them:Table 1:Company This_Year_SalesDisney 1000Pepsi 2000Table 2:Company Last_Year_SalesCoke 3000Target 1000I want to join these tables together so that all the information is presented, with three columns: Company, This_Year_Sales, Last_Year_Sales, like this:Company This_Year_Sales Last_Year_SalesDisney 1000 n/a Pepsi 2000 n/aCoke n/a 3000Target n/a 1000How do I do it? |
|
russell
Pyro-ma-ni-yak
5072 Posts |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-25 : 15:45:46
|
Union All.SELECT Company, This_Year_Sales, NULL AS Last_Year_Sales FROM Table1UNION ALLSELECT Company, NULL AS This_Year_Sales, Last_Year_Sales FROM Table2--Gail ShawSQL Server MVP |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-26 : 12:25:40
|
what if same company appears in this year and last year sales? you want to show them in 1 or 2 rows?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|