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
 

 

How to query second maximum rows and 5th max row

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
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    Post subject: How to query second maximum rows and 5th max row
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

Site Director


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

PostPosted: Thu Jan 04, 2007 10:49 pm    Post subject:
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 6:49 am    Post subject: Re: how to query second maximum rows and 5th max row
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jan 05, 2007 1:59 pm    Post subject: Re: how to query second maximum rows and 5th max row
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    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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