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)
 Different queries into a single query

Author  Topic 

kagitas
Starting Member

2 Posts

Posted - 2004-07-25 : 00:20:17
Hi,
I have few queries with me
Say :
A) Select A from AAA
B) Select B from BBB
C) Select C from CCC
what i would like to know is can i put the above queries into a single query.
Thanks in advance,
Jaya....

kselvia
Aged Yak Warrior

526 Posts

Posted - 2004-07-25 : 02:04:03
You can combine all results with UNION.

SELECT A FROM AAA
UNION ALL
SELECT B FROM BBB
UNION ALL
SELECT C FROM CCC


--Ken
Your Kung-Fu is not strong. -- 'The Core'
Go to Top of Page

kagitas
Starting Member

2 Posts

Posted - 2004-07-26 : 01:31:07
Thank you very much kselvia but what i am expecting is
A) Select A from AAA
B) Select B from BBB
C) Select C from CCC
into a single result set
ColA ColB ColC
as output: A B C
1st row a1's b1's c1's
2nd row a2's b2's c2's
3rd row a3's b3's c3's
4th row a4's b4's c4's

Can you give me solution for this.
Thanks in advance
Jaya..


Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-26 : 01:45:04
Do you have a rownumber on each field or something that relates the tables? Your example doesn't make any sense really. Why don't you give us the CREATE TABLE for the three tables, some sample INSERT statements for each table, and a result set that you are expecting from the sample data.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-26 : 01:51:22
Maybe something like
[code]
SELECT A, B, C
FROM AAA
LEFT OUTER JOIN BBB
ON BBB.ID = AAA.ID
LEFT OUTER JOIN CCC
ON CCC.ID = AAA.ID
ORDER BY AAA.ID
[code]
Kristen
Go to Top of Page
   

- Advertisement -