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

How to query second maximum rows and 5th max row


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Thu Jan 04, 2007 10:10 pm
Reply with quote

hai all
i have doubt
i want to query
find a second max row and 5th max row
how we write a query
by
raj
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 04, 2007 10:49 pm
Reply with quote

Hello,

Please post some sample data and what you need the output to be.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Thu Jan 04, 2007 10:52 pm
Reply with quote

just take one table
it contain so many records
filed is empname, salary, dept
i want who is second highest salary person
and another who is 5 th highest salary person
by
raj
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 6:49 am
Reply with quote

I bet this one is going to top the list of popularity amongst regular questions being asked.

Take a look here... Previously Discussed...

Also it might help others if you use SEARCH facility before posting your questions.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Fri Jan 05, 2007 9:39 am
Reply with quote

Code:
SELECT MAX(SALARY) FROM EMP_TABLE A WHERE 5=(SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY<=B.SALARY);


For Nth Maximum Value:-
Code:
SELECT SALARY FROM EMP_TABLE A WHERE (N-1) IN (SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY < B. SALARY);


i have one table only not two tables
i have little bit confuse here how it comes table
B

my query is only one table not from two tables
i want to reterive the data from one table A only

by
raj
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 1:59 pm
Reply with quote

Raj,
Quote:
my query is only one table not from two tables
i want to reterive the data from one table A only

Did you execute the query or NOT?

Its not two tables... Its just kind of image of a single table... I would not go in further details of ALIAs, which is what this called...
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts RC query -Time column CA Products 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
Search our Forums:

Back to Top