View previous topic :: View next topic
|
Author |
Message |
itssrikanth4u
New User
Joined: 21 Nov 2004 Posts: 9
|
|
|
|
Hi,
Can any one please tell me the best optimum query to find nth highest salary?
bye
thanx in advance
take care
srikanth |
|
Back to top |
|
|
ovreddy
Active User
Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
|
|
|
|
Hi,
Here is a way in which we can find nth max or top n max salaries from emp table...
SELECT SAL FROM EMP A WHERE N<=(SELECT COUNT(DISTINCT SAL) FROM EMP B WHERE A.SAL<=B.SAL);
This is one way to find top n salaries. But execute this and check EXPLAIN results so that u will get exact optimization. If you have any other queries an your mind apply Explain on them and compare... ok
Bye,
Reddy. |
|
Back to top |
|
|
jz1b0c
Active User
Joined: 25 Jan 2004 Posts: 160 Location: Toronto, Canada
|
|
|
|
Srikanth,
This was answered earlier,
SELECT *
FROM TEST.TABLE1 T1
WHERE 5 = ( SELECT COUNT(DISTINCT T2.NUM)
FROM TEST.TABLE2 T2
WHERE T2.NUM >= T1.NUM)
ORDER BY NUM DESC ;; |
|
Back to top |
|
|
|