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?

Thanks
greddinAsked:
Who is Participating?
 
BrandonGalderisiConnect With a Mentor Commented:
select collectionid, doctype,count(*) as 'Count'
from YourDocumentTable
group by collectionid, doctype
0
 
dhanushkadCommented:
Code you please explain it more..
0
 
dhanushkadCommented:
Could you please explain your question with some samples..
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
greddinAuthor Commented:


First first select statement returns a list of CollectionIDs Like this:
 
CollectionID
------
1
2
3
4
5
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

0
 
dhanushkadCommented:
IS the above comment is what your looking for ?
or
do you have two seperate queries for frist and secrion statements. >
0
 
greddinAuthor Commented:
Right now I have two separate queries that run on different tables of the same database.
0
 
dhanushkadCommented:
what r the queries ?
0
 
greddinAuthor Commented:
Thanks for this response. Based on this I was able to get what I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.