title: Sql Server Max function on multiple columns?
body: <p>Below is my table data </p>
  
  <pre><code> Mat   Phy Chem
   20 30  40
   25 35  35
   45 30  30
   45 40  35
  </code></pre>
  
  <p>I want to retrieve top 3 max rows of all the three columns in a single row.</p>
  
  <p>O/P</p>
  
  <pre><code> Mat  Phy Chem
   45   40   40
   25   35   35
   20   30   30
  </code></pre>
  
  <p>I have used below query but was unsuccessful, please help...</p>
  
  <pre><code>Select distinct top 3 max(mat) from studata group by mat order by max(mat) desc
  Union all
  Select distinct top 3 max(phy) from studata group by phy order by max(phy) desc
  Union all
  Select distinct top 3 max(chem) from studata group by chem order by max(chem) desc
  </code></pre>