IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Returning a column which corresponds to a MAX value


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
PokerGuru

New User


Joined: 23 Jul 2010
Posts: 33
Location: Europe

PostPosted: Thu Oct 27, 2011 8:58 pm
Reply with quote

Hi,

The table contains the following:
APAR_ID TAPE_SERIES N:REQUEST_ID APAR_ORDER_NO
ZA04450 TEL999 N R00696 3
ZA04452 TEL999 N R00696 1
ZA04451 TEL999 N R00696 2

I am trying to return the APAR ID which corresponds to the MAX APAR_ORDER_NO, so that would be ZA04450
Here is my query:
Code:

SELECT MAX(APAR_ORDER_NO),
APAR_ID
INTO
:max_apar_ord_no,
:apar_id_db
FROM STCUTSTG.CUT_APAR_TAPE
WHERE REQUEST_ID = 'R00696'
GROUP BY APAR_ID


I am getting the following error:
"Additional rows of data remain. One row returned."
So I know it is selecting all three APAR ID's because all three have a request id = R00696, but how can I specify properly to select the APAR_ID with the largest APAR_ORDER_NO
Any hints as to what's wrong?
Thanks
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Oct 27, 2011 9:22 pm
Reply with quote

Code:
SELECT APAR_ORDER_NO , APAR_ID
INTO
:max_apar_ord_no,
:apar_id_db
FROM STCUTSTG.CUT_APAR_TAPE A
WHERE REQUEST_ID = 'R00696'
and APAR_ORDER_NO =
      (select MAX(APAR_ORDER_NO)
        FROM STCUTSTG.CUT_APAR_TAPE  B
      where A.REQUEST_ID =B.REQUEST_ID )
Back to top
View user's profile Send private message
PokerGuru

New User


Joined: 23 Jul 2010
Posts: 33
Location: Europe

PostPosted: Thu Oct 27, 2011 9:27 pm
Reply with quote

Thanks Guy C
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Split a record with data in a differe... DFSORT/ICETOOL 8
Search our Forums:

Back to Top