Help with SQL statement

I have a couple of different sql queries that each in their own right give me what I need. But I would like to merge the two together as one report.

Is it possible to have an outer select with an inner select?  

The first select is returning an ID. On the second (inner) select I would like to pass in the ID from the outer select.

How could I do this?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Code you please explain it more..
Could you please explain your question with some samples..
greddinAuthor Commented:

First first select statement returns a list of CollectionIDs Like this:
and so on
My second query does takes a given CollectionID and counts a DocType that are in each CollectionID.
Like this:
DocType   Total
-------   -----
 type1      12
 type2       6
 type3       8
 type4       2
 type5      16
I would somehow like to merge these two results into one and return something like this:
CollectionID  DocType  Count
------------  -------  -----
     1         type1     12
     1         type2      6
     1         type3      8
     1         type4      2
     1         type5     16
     2         type1      2
     2         type2     10
     2         type3      5
     2         type4      3
     2         type5      9
..continue until all CollectionIDs are done.
Does this make sense?

Open in new window

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

select collectionid, doctype,count(*) as 'Count'
from YourDocumentTable
group by collectionid, doctype

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IS the above comment is what your looking for ?
do you have two seperate queries for frist and secrion statements. >
greddinAuthor Commented:
Right now I have two separate queries that run on different tables of the same database.
what r the queries ?
greddinAuthor Commented:
Thanks for this response. Based on this I was able to get what I needed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.