title: Group by on two fields with different value and choosing specific value by order
body: <p>I have been searching for the solution to this problem but still couldn't find the most similar problem than this <a href="https://stackoverflow.com/questions/50024035/sql-group-by-column-choose-specific-rows">SQL Group BY COLUMN Choose specific rows</a> .</p>
  
  <p>So here is my problem</p>
  
  <pre><code>     Type_Table
  column1  |   column2
  a        |   s
  a        |   m
  a        |   e
  b        |   s
  b        |   e
  c        |   m
  c        |   s 
  </code></pre>
  
  <p>so basically i want to group by column1 but choosing only the values in column2 = e, but if it is not exist in the duplicated value in column1 then choosing column2 = s, but if it is not exist in the duplicated value column1 then choosing column2 = m.
  So the resulting table would look like this</p>
  
  <pre><code>column1  |   column2
  a        |   e
  b        |   e
  c        |   s 
  </code></pre>
  
  <p>I've used this
  <code>select column1,case when column2=e then e when column2=s then s when column2=m then m end column2 from type_table group by 1</code> but it's obviously not gonna work. What i need is group by column1 and for every different value in column2 choose only e if exist for their respective column1 value but choose s if e doesnt exist and choose m if s doesnt exist.
  Thanks for your answers </p>