title: mySQL query to select on the max value of one field  with another field common
body: <p>1I am trying to write a message table with conversation threads like gmail. (I use php). The table is as shown. posID means the position of each message in a given threadID.</p>
  
  <pre><code>id | senderID | recvrID |  message(threadID,posID)  | threadID | posID |   time 
  1       1          3            msg 1,1                  1          1       12pm
  2       3          1            msg 1,2                  1          2        3pm
  3       1          2            msg 2,1                  2          1        1pm
  </code></pre>
  
  <p>I need to write a query to find all msg threads to senderID=1 (in this case), and if there are more than one msgs in a thread, select the last msg only in each thread (can sort by positionID or time).</p>
  
  <p>expected output is a table as follows.</p>
  
  <pre><code> senderID      |  message                 | Time
     1               msg 1,2                  3pm
     1               msg 2,1                   1pm
  </code></pre>
  
  <p>Edit:
  After more reading, I guess I need to select messages with the sender/ receiver constraints, AND ( if more than one messages in a thread, only those messages with MAX(posID) for each threadID). Dont know how to implement this.</p>