title: sql get row with max date and relative id record
body: <p>I try to make a simple query, spent on it a tone of hours and get nothing....<br>
  All I need is to get MAX date and all is corresponding fields.</p>
  
  <p>I'm explain:
  I have a table with this fields: <code>BasketID</code>, <code>OrderStatusTypeID</code>, <code>StatusDate</code>.<br>
  I try to get only one record that contain <code>OrderStatusTypeID</code> value with the last <code>StatusDate</code>.</p>
  
  <p><strong>This is the data</strong></p>
  
  <pre><code>BasketID    OrderStatusTypeID   date
  1111        13              2013-04-01 11:38:31
  1111        26              2013-04-04 17:44:17
  1111        39              2013-04-02 12:35:07
  1111        40              2013-04-08 12:52:55
  </code></pre>
  
  <p><strong>This is my query:</strong></p>
  
  <pre><code>SELECT BasketID, OrderStatusTypeID, max(StatusDate) date
  FROM st
  where BasketID=1111
  group by BasketID
  </code></pre>
  
  <p><strong>This is the results i need</strong></p>
  
  <pre><code>BasketID    OrderStatusTypeID   date
  63558       40          2013-04-08 12:52:55
  </code></pre>
  
  <p>For some reason I only get <code>OrderStatusTypeID = 13</code> and not <code>40</code>!
  (max of StatusDate, and NOT max of OrderStatusTypeID).<br>
  Why???</p>
  
  <pre><code>BasketID    OrderStatusTypeID   date
  63558       13                   2013-04-08 12:52:55
  </code></pre>
  
  <p><strong>Thanks for fast response!</strong></p>