MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

select the fourt max record from a table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
dohellwithmf
Beginner


Joined: 12 Jul 2007
Posts: 55
Topics: 23

PostPosted: Thu Aug 02, 2007 5:03 am    Post subject: select the fourt max record from a table Reply with quote

Hi all,
please let me know the query to select the fourth maximum record from a table.

do we have a function to do so?


Question
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Aug 02, 2007 5:54 am    Post subject: Reply with quote

no function. solved using Correlated Subselect

sample queries have been provided many times.
use the search feature of this forum.

Since you did not deem it appropriate to provide any details, I am providing a solution that will work if you are using Vsn7 or above:
Code:

SELECT SALARY, EMPNO, LASTNAME
FROM   EMP  E1
WHERE  4 > (SELECT COUNT(*)
             FROM   EMP E2
             WHERE  E1.SALARY < E2.SALARY)
ORDER BY 1 ASC
FETCH FIRST ROWS ONLY;


Change the '4' in the WHERE clause to whatever when you wish a different ?th.

again, I feel that this is a student or interview question and should not be put in this forum, but instead in the appropriate Interview forum.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group