Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Print first 5 max salary using SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
raviprasath_kp
Warnings : 1

Active User


Joined: 20 Feb 2005
Posts: 66
Location: chennai

PostPosted: Wed Jun 06, 2007 8:26 pm    Post subject: Print first 5 max salary using SQL
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
References
Craq Giegerich

Senior Member


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

PostPosted: Wed Jun 06, 2007 9:13 pm    Post subject: Re: max salary qurey
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    Post subject: Re: Print first 5 max salary using SQL
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1