title: Greatest of three columns in SQL
body: <p>I want to compare multiple columns and come with the maximum value among different columns</p>
  
  <p>For three columns I came up with the below query which works fine </p>
  
  <pre><code>SELECT CASE
           WHEN col1 &gt;= col2
                AND col1 &gt;= col3 THEN col1
           WHEN col2 &gt;= col1
                AND col2 &gt;= col3 THEN col2
           WHEN col3 &gt;= col1
                AND col3 &gt;= col2 THEN col3
           ELSE col1
         END AS Max_number 
      FROM   (VALUES (1,2,3),
                     (1,2,3),
                     (1,2,3)) tc (col1, col2, col3) 
  </code></pre>
  
  <p>But things are getting complicated when I want to compare more than 3 columns. Is there any simpler way to do this</p>