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 use Where Clause in UNION ?

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-19 : 05:37:12
Hello All,
I have a query which uses Union.
Query is working fine but i want to apply a where clause on the result set which is selection by Query1 Union Query 2.

Can any one help me?

Thanks
Sample Query is like this

select Col1,Col2 from table1
Union
selection Col1,Col2 from table2

(and I want to apply the where clause on result of above mentioned query)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-19 : 05:38:35
[code]select *
from
(select Col1,Col2 from table1
Union
select Col1,Col2 from table2
)t
where yourconditions[/code]
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-19 : 05:42:20
[code]
select Col1,Col2 from table1
where somecondition
Union
selection Col1,Col2 from table2
where somecondition2
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -