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
 forming query in SQL without union

Author  Topic 

subhaoviya
Posting Yak Master

135 Posts

Posted - 2012-06-22 : 06:05:05

Having 2 tables A and B
A B
C1 C1
1 1
2 2
5 3
6 4
How to produce resultset
C1
1
2
3
4
5
6 without using union operator

waterduck
Aged Yak Warrior

982 Posts

Posted - 2012-06-22 : 06:52:25
select distinct case when a.c1 < b.c1 then b.c1 else a.c1 end from a a cross join (select * from b) b
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-23 : 00:04:29
[code]
select DISTINCT COALESCE(t1.C1,t2.C1) AS C1
from table t1
full join table t2
on t2.C1 = t1.C1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -