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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am


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