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

Print first 5 max salary using SQL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
raviprasath_kp
Warnings : 1

New User


Joined: 20 Feb 2005
Posts: 65
Location: chennai

PostPosted: Wed Jun 06, 2007 8:26 pm
Reply with quote

Hi i have one db2 table

i want to print first 5 max salary

any one can suggest some qurey for that
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 06, 2007 9:13 pm
Reply with quote

raviprasath_kp wrote:
Hi i have one db2 table

i want to print first 5 max salary

any one can suggest some qurey for that


Here it is. Expect terrible response time. icon_cry.gif
Code:
SELECT MAX(SALARY) FROM SALARYS                           
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS) 
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS))
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS)))
UNION ALL                                                         
SELECT MAX(SALARY) FROM SALARYS                           
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS   
WHERE SALARY < (SELECT MAX(SALARY) FROM SALARYS))))
ORDER BY 1 DESC;
Back to top
View user's profile Send private message
Abirami.YN

New User


Joined: 16 Jul 2005
Posts: 15
Location: India - Chennai

PostPosted: Thu Jun 07, 2007 1:09 pm
Reply with quote

Hi,

Try this query to fetch first 5 maximum salary amount

SELECT SALARY FROM SALTABLE
ORDER BY SALARY DESC
FETCH FIRST 5 ROWS ONLY


Regards
Abirami
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts JCL sortcard to print only the records DFSORT/ICETOOL 11
No new posts is there a way to print time in HH:MM... SYNCSORT 12
No new posts Print out all lines with 'IBM' compil... CLIST & REXX 8
No new posts Back Page print direction (Duplex Pri... JCL & VSAM 3
No new posts Print report for each record from mul... CA Products 1
Search our Forums:

Back to Top