title: sql query to find top 5 earners in a company(oracle db)
body: <p>My emp table:</p>
  
  <pre><code>ENAME             SAL
  ---------- ----------
  KING             5000
  SCOTT            3000
  FORD             3000
  JONES            2975
  BLAKE            2850
  CLARK            2450
  </code></pre>
  
  <p>for getting top 5 earners.i used the below query.</p>
  
  <pre><code>SELECT  * 
  FROM (SELECT ename, sal 
       from emp 
       ORDER BY sal desc)
  WHERE rownum &lt;= 5  
  order by sal desc;
  </code></pre>
  
  <p>but I am getting output like this:</p>
  
  <pre><code>ENAME             SAL
  ---------- ----------
  KING             5000
  SCOTT            3000
  FORD             3000
  JONES            2975
  BLAKE            2850
  </code></pre>
  
  <p>In this list, 'CLARK' is missing.</p>
  
  <p>Employee 'CLARK' is also in top 5 earners list.how will I get if same salaries in the list. 
  if I use dense_rank  ,'CLARK' will come on the list.</p>
  
  <pre><code> SELECT  *  from 
  (SELECT ename,SAL,DENSE_RANK() OVER(ORDER BY SAL DESC) AS RK FROM EMP)
  WHERE RK &lt;= 5
  ORDER BY SAL DESC;
  
  
  
  ENAME             SAL         RK
  ---------- ---------- ----------
  KING             5000          1
  SCOTT            3000          2
  FORD             3000          2
  JONES            2975          3
  BLAKE            2850          4
  CLARK            2450          5
  </code></pre>