Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested query question

Status
Not open for further replies.

mikej336

MIS
Feb 10, 2005
164
US
Basically have 2 quaeries. The first one brings back a basic selection. The second one groups and counts the first one.

SELECT substr(sfid,1,6) AS test, SFCODE, SVCID, SVCOTY
FROM SVCYAD/SVCFT, SVCYAD/SRVMAST99 WHERE
SFCODE = 'A2 '

SELECT test, SFCODE, SVCOTY, count(svcoty)
FROM
GROUP BY test, SFCODE, SVCOTY

That I need to run as one query. I can only find basic examples of what to do.

I have tried...

SELECT test, SFCODE, SVCOTY, count(svcoty)
FROM (SELECT substr(sfid,1,6) AS test, SFCODE, SVCID, SVCOTY FROM SVCYAD/SVCFT, SVCYAD/SRVMAST99 WHERE
SFCODE = 'A2 ') as bla
GROUP BY test, SFCODE, SVCOTY

Trying to run this on AS400/DB2 if that makes a difference.

Thanks

M
 
What is the error you're seeing? The first thing that jumps out that I would change is to use the table correlation name in the outer select...

Code:
SELECT bla.test, bla.SFCODE, bla.SVCOTY, count(svcoty)
 
Why not simply this ?
SELECT substr(sfid,1,6) AS test, SFCODE, SVCOTY, count(svcoty)
FROM SVCYAD/SVCFT, SVCYAD/SRVMAST99
WHERE SFCODE = 'A2 '
GROUP BY substr(sfid,1,6), SFCODE, SVCOTY

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top