title: How to sort by date but group on a certain column value SQL
body: <p>I have a table that looks like this.</p>
  
  <pre><code>my_id |    date
  -------------------  
    1   | 2013-04-01
    1   | 2013-04-02
    2   | 2013-04-03
    1   | 2013-04-04
    3   | 2013-04-05
    2   | 2013-04-06
  </code></pre>
  
  <p>I would like a SQL query that gives this result.</p>
  
  <pre><code>my_id |    date
  -------------------  
    2   | 2013-04-06
    2   | 2013-04-03
    3   | 2013-04-05
    1   | 2013-04-04
    1   | 2013-04-02
    1   | 2013-04-01
  </code></pre>
  
  <p>So I want all with the same my_id to be together with date descending order. And the groups of my_id's should be sorted on date descending based on the latest date in the groups.</p>
  
  <p>It is like a threaded conversation you could say, were my_id is the conversation id and the date is the dates of the posts to that conversation. So when showing in a list the conversation with the most recent post should be on top.</p>
  
  <p>Follow up question
  If my_id is NULL they should not be grouped together but still sorted by date. This would be if they are not part of a conversation for example.</p>
  
  <pre><code>my_id |    date
  -------------------  
    1   | 2013-04-01
    1   | 2013-04-02
    2   | 2013-04-03
    1   | 2013-04-04
   NULL | 2013-04-05
    2   | 2013-04-06
   NULL | 2013-04-07
  </code></pre>
  
  <p>The table above would then be like this</p>
  
  <pre><code>my_id |    date
  -------------------  
   NUll | 2013-04-07
    2   | 2013-04-06
    2   | 2013-04-03
   NULL | 2013-04-05
    1   | 2013-04-04
    1   | 2013-04-02
    1   | 2013-04-01
  </code></pre>