Grouping columns into conversations

Hi,

I’ve been struggling to update an old messaging script to a conversational view.

What I have at the moment is a PMs database that looks a bit like this:

[table=“width: 500”]
[tr]
[td]message_id[/td]
[td]subject[/td]
[td]from_uid[/td]
[td]to_uid[/td]
[td]time[/td]
[/tr]
[tr]
[td]1[/td]
[td]Hey mate[/td]
[td]300[/td]
[td]100[/td]
[td]1332694635[/td]
[/tr]
[tr]
[td]2[/td]
[td]Hey mate[/td]
[td]100[/td]
[td]300[/td]
[td]1332694835[/td]
[/tr]
[tr]
[td]8[/td]
[td]Hey mate[/td]
[td]300[/td]
[td]100[/td]
[td]1332694935[/td]
[/tr]
[tr]
[td]14[/td]
[td]Hey mate[/td]
[td]100[/td]
[td]300[/td]
[td]1332695835[/td]
[/tr]
[/table]
…etc

What I have been trying to do is combine to and from messages, and set a new column “conversation id”.

This would group related messages under 1 id (the message_id of the earliest message) and show as a group of both to and from.

Tried grouping by to_userid and using it to set a conversation_id. It worked, but I couldn’t also group the reverse (e.g. replies from from_id to to_id).

Would anyone have any idea on how to go about doing this?

Many thanks,
Jbcubed3

mind showing what the result of this combining would produce for the sample data you gave?

don’t forget that GROUP BY is an aggregation operation which destroys individual detail rows