title: How to find the nth highest value in a table in SQL Server
body: <p>What is the logic in the below query to find the nth highest value in the table?</p>
  
  <pre><code>select * 
  from tablename as a 
  where (n-1) = (select count(distinct(column name) 
                 from tablename as b 
                 where b.columname &gt; a.columnname)
  </code></pre>
  
  <p>Example query: </p>
  
  <pre><code>select * 
  from tblperson a 
  where 3 = (select count(distinct(expenses)) 
             from tblperson b 
             where b.Expenses &gt; a.Expenses)
  </code></pre>