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
 Query a query?

Author  Topic 

davers
Starting Member

14 Posts

Posted - 2008-05-27 : 08:49:14
Hi everyone. Is it possible to combine data from 2 queries into 1 query? I have a database that houses a departments info. The query returns: DEPT_NUM, DEPT_GROUP

I have another database that houses their statistics and num. The query returns: DEPT_NUM, DEPT_STATS

I'd like a query that combines the 2 and gives me: DEPT_NUM, DEPT_GROUP, DEPT_STATS.

Is something like that possible?

Thanks for any help!

Dave

Windows XP, Office XP

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-27 : 08:54:31
[code]Select q1.DEPT_NUM, q1.DEPT_GROUP, q2.DEPT_STATS
From
(... First Query) q1 join (... Second query) q2
on q1.DEPT_NUM = q2.DEPT_NUM[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

davers
Starting Member

14 Posts

Posted - 2008-05-27 : 14:28:25
Thanks! That's exactly what I had in mind!

Dave

Windows XP, Office XP
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-27 : 14:30:02
You need to study JOINS in Books Online.
Go to Top of Page
   

- Advertisement -