I have following data in database
MAILFROM, MAILTO , TIMESTAMP, MESSAGE
A B 2013-07-01 12:11:12, Hi
B A 2013-07-01 12:12:12, Hi back
A B 2013-07-01 12:13:12, How are you
A C 2013-07-01 12:14:12, Hi there
D A 2013-07-01 12:16:12, Hi
C D 2013-07-01 12:17:12, Hi
How do I group this with select so I get
A C 'comment occurs 3 times
SELECT MAILFROM, MAILTO FROM messages WHERE 'A' IN(FROM,TO) GROUP BY FROM
gives
A C as well as C A but I want combination combined together.
that it only shows A C 3 times
The example is a mailbox.
This contains:
MAILFROM, MAILTO , TIMESTAMP, MESSAGE
A B 2013-07-01 12:11:12, Hi
B A 2013-07-01 12:12:12, Hi back
A B 2013-07-01 12:13:12, How are you
A C 2013-07-01 12:14:12, Hi there
D A 2013-07-01 12:16:12, Hi
C D 2013-07-01 12:17:12, Hi
SQL listing should list this (unique conversations)
B 2013-07-01 12:13:12, "Hi" ' Remark Timestap of the latest message
C 2013-07-01 12:14:12, "Hi there"
D 2013-07-01 12:16:12, "Hi"
C D 2013-07-01 12:17:12, "Hi" ' THIS SHOULD NOT BE SHOWN
This means this sql will list the messages he have as sender and as receiver (from,to). It should only list between this person and the one sent to no matter who is MAILFROM or MAILTO. timestamp is the date of the latest message between them... Remark he never send to D, a is listed anyhow, to C he sent but didn not get back anything... between B is 3 messages. so output should be only these 3 rows..