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)
 Returning in table called order using UNION

Author  Topic 

Mooo0
Starting Member

4 Posts

Posted - 2008-04-23 : 22:07:45
Hello again,

I am using UNION to return these 2 tables:

TableA
QID Q
1 Name?
2 Age?
3 Phone?

TableB
QID Q
1 DogName?
2 CatName?


When I use the following query;
SELECT * FROM TableA UNION SELECT * FROM TableB

I get the following return:
QID Q
1 whateverquestions
1
2
2
3

but I wish it to return in order of table invoke:
QID
1
2
3
1
2


Is that possible? (by not changing QID)

Cheers,

James

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-04-23 : 23:10:52
select *, 1 as seq from tablea
union
select *, 2 as seq from tableb
order by seq, qid
Go to Top of Page

Mooo0
Starting Member

4 Posts

Posted - 2008-04-23 : 23:47:01
Fantastic!

Cheers!
Go to Top of Page
   

- Advertisement -