I've read a lot of questions and answers related to this topic, but I can't find anything that's working for me, so I could really use some help.
I am trying to make a simple private messaging system for my website. I have a table like this:
private messages: id, to_id, from_id, message, time_sent
I am now trying to show a list on my page with the different users a member interacted with, something like Facebook messages so every name should appear only once in the list.
This is what I have now which shows me every message that I as a user ($my_id) participate in:
SELECT * FROM private_messages WHERE (from_id = '$Sid' AND to_id = '$my_id') OR (from_id = '$my_id' AND to_id = '$Sid') ORDER BY time_sent ASC
This query shows a distincted list, but only of the people that I received a message from:
SELECT DISTINCT(from_id) FROM private_messages WHERE to_id='$my_id' ORDER BY time_sent DESC
How should I rewrite this so it gives me a distinct list of every user that I interacted with (like a list of facebook messages)? I think I need to distinct on two columns, from_id and to_id, but how should I do it?
I know the questions sounds rather vague, but I really can't explain it any better. Thanks in advance!