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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to UNION columnwise?

Author  Topic 

karthi2009
Starting Member

23 Posts

Posted - 2009-11-10 : 02:43:50
Hi,

I have two tables as below:

Table 1:
--------------------
Items | Qty (Sold)
--------------------
Item-1 | 3
Item-2 | 4
Item-4 | 7
====================

Table 2:
--------------------
Items | Qty (Remaining)
--------------------
Item-1 | 5
Item-2 | 6
Item-4 | 10
====================

I want to show results as follows:

----------------------------------------
Items | Qty (Sold) | Qty (Remaining)
----------------------------------------
Item-1 | 3 | 5
Item-2 | 4 | 6
Item-4 | 7 | 10
========================================

Please guide me in this regard,

Thanks in advance,

Karthikeyan

Sachin.Nand

2937 Posts

Posted - 2009-11-10 : 02:45:37
why you want to use UNION?A simple join can do it for you.

PBUH
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-11-10 : 02:49:02
select
t1.item,
t1.sold
t2.remaining
from table1 t1
left join table2 t2 on t2.items = t1.items


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -