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 2000 Forums
 SQL Server Development (2000)
 union of 2 tables and where condition

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-02-16 : 14:20:33
how can i make union on 2 tables and add a where condition that will effect both of them?
beacuse if i do

select * from table1
union all
select * from table2
where id>5

the where effects only the second select!
what to do?
thnaksi nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-16 : 14:48:05
Suggestion 1.

select * from table1 where id>5
union all
select * from table2 where id>5

Suggestion 2.

Select ID, field1,... from
(select ID, field1,... from table1
union all
select ID, field1,... from table2) as UnionQry
where id > 5


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-17 : 02:24:35
First approach is correct way to go.

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -