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.
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
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).
expected output is a table as follows.
senderID | message | Time
1 msg 1,2 3pm
1 msg 2,1 1pm
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.