hmm måske forstår jeg ikke dit problem rigtigt... men for mig er løsningen ret simpel:
SELECT c.*, MAX(m.time) as latest_post
FROM conversations as c
INNER JOIN messages as m ON c.id = m.conversation_id
WHERE c.userId = 222 OR c.friendId = 222
GROUP BY c.id
ORDER BY latest_post DESC
her er mine testdata:
Samtaler:
id userId friendId
1 222 333
2 222 444
Beskeder:
id message time (Desc) conversation_id
14 rty 2012-05-14 19:59:55 2
13 cvb 2012-05-14 19:59:51 1
12 dfg 2012-05-14 19:59:46 2
11 ert 2012-05-14 19:59:42 1
1 foo 2012-05-14 19:22:57 2
2 bar 2012-05-14 19:22:57 2
3 foo 2012-05-14 19:14:13 1
8 wer 2012-05-13 19:59:37 2
9 sdf 2012-05-13 19:59:24 1
10 xcv 2012-05-11 19:59:32 2
4 bar 2012-05-10 19:58:06 1
6 zxc 2012-05-08 19:59:17 2
5 asd 2012-05-08 19:58:56 1
7 qwe 2012-05-04 19:59:20 1
Forespørgselsresultat:
id userId friendId latest_post
2 222 444 2012-05-14 19:59:55
1 222 333 2012-05-14 19:59:51
Hvis det ikke er det... ignorer bare mit svar :P
Håber dette hjælper