title: Nth max salary query in SQL
body: <p>I have a table; containing 2 fields, name and salary. I used below script to find the 3rd maximum salary.</p>
  
  <pre><code>SELECT DISTINCT sal 
  FROM downtodate1.emp e1  
  WHERE 3 = (SELECT COUNT(DISTINCT sal) FROM downtodate1.emp e2 WHERE e1.sal&lt;= e2.sal);
  </code></pre>
  
  <p>I want to know how it works and why 3 is used here?</p>