title: SQL MAX function in non-numeric columns
body: <p>As far as I understand the MAX function, it shall return a maximum value from a given column. In case of numeric values, for example a salary column, it is clear for me - and this is the only application I find in tutorials. However, I have a problem to understand how does it work in case of non-numeric columns. </p>
  
  <p>My problems originates from this exercise (on sql-ex.ru)</p>
  
  <p><em>Find out makers who produce only the models of the same type, and the number of those models exceeds 1.</em>
  The table "Product" includes information about the maker, model number, and type ('PC', 'Laptop', or 'Printer').
  One of the solutions to this is:</p>
  
  <pre><code>SELECT maker,
         MAX(type) AS type
  FROM   product
  GROUP  BY maker
  HAVING COUNT(DISTINCT type) = 1
         AND COUNT(model) &gt; 1 
  </code></pre>
  
  <p>I don't understand the function of max - what does it count? I tried a simpler query to understand it, but it only made it more difficult.</p>
  
  <pre><code>SELECT maker,
         MAX(type) AS type, COUNT(type) AS QTY
  FROM product
  GROUP BY maker
  ORDER BY maker
  </code></pre>
  
  <p>The returned set was</p>
  
  <pre><code>maker  type      QTY
  A      Printer   7
  B      PC        2
  C      Laptop    1
  D      Printer   2
  E      Printer   4
  </code></pre>
  
  <p>The MAX(type) seems to me to show a random value e.g. why for the maker B the result is PC and not Laptop? Why for E it is Printer and not PC?  </p>
  
  <p>Full Table<br>
   <img src="https://i.stack.imgur.com/gObvQ.png" alt="http://i.stack.imgur.com/gObvQ.png"></p>