× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

If you are on release V5R4 you can use OLAP Ranking Functions to archieve
this:
With x as (Select a.*,
rownumber() over(Order By Key1 Desc, Key2 Desc ...KeyN
Desc) as Counter
from MyTable a
Where ....)
Select a.*
from x
Where Counter = 2;

If you are not yet on release you may try the following:
With x as (Select a.*
from MyTable a
Where ...
Order By Key1 Desc, Key2 Desc ... KeyN Desc
Fetch First 2 Rows Only)
Select a.*
from x
Order By Key1, Key2, ... KeyN
Fetch First Row only;

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Shailendra Tewatia
Gesendet: Thursday, April 19, 2007 06:41
An: rpg400-l@xxxxxxxxxxxx
Betreff: How to get second highest record usig sql/400.


Hi Gurus,
Is there any built in function to get the second highest record.


Advance thanks
Shail


DISCLAIMER:
This message (including attachment if any) is confidential and may be
privileged. Before opening attachments please check them for viruses and
defects. MindTree Consulting Limited (MindTree) will not be responsible for
any viruses or defects or any forwarded attachments emanating either from
within MindTree or outside. If you have received this message by mistake
please notify the sender by return e-mail and delete this message from your
system. Any unauthorized use or dissemination of this message in whole or in
part is strictly prohibited. Please note that e-mails are susceptible to
change and MindTree shall not be liable for any improper, untimely or
incomplete transmission.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.