|
View previous topic :: View next topic
|
| Author |
Message |
PokerGuru
New User

Joined: 23 Jul 2010 Posts: 33 Location: Europe
|
|
|
|
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 |
|
 |
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
| 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 |
|
 |
PokerGuru
New User

Joined: 23 Jul 2010 Posts: 33 Location: Europe
|
|
|
|
| Thanks Guy C |
|
| Back to top |
|
 |
|
|