Link to home
Start Free TrialLog in
Avatar of greddin
greddinFlag for United States of America

asked on

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
Avatar of dhanushkad
dhanushkad

Code you please explain it more..
Could you please explain your question with some samples..
Avatar of greddin

ASKER



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

ASKER CERTIFIED SOLUTION
Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IS the above comment is what your looking for ?
or
do you have two seperate queries for frist and secrion statements. >
Avatar of greddin

ASKER

Right now I have two separate queries that run on different tables of the same database.
what r the queries ?
Avatar of greddin

ASKER

Thanks for this response. Based on this I was able to get what I needed.