Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Returning a column which corresponds to a MAX value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Returning a column which corresponds to a MAX value
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: 1280
Location: Belgium

PostPosted: Thu Oct 27, 2011 9:22 pm    Post subject:
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    Post subject: Reply to: Returning a column which corresponds to a MAX valu
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 6 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us