Joined: 06 Dec 2004 Posts: 200 Location: Keane India Ltd., Hyderabad
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