I have a simple table maintaining messages between users. The table structure looks like
sender receiver message sendtime 1 2
I take 30 mins to find the solution for this problem because I have thew same problem just take it simple
SELECT DISTINCT sent_by FROM messages WHERE sent_to = 1 UNION SELECT DISTINCT sent_to FROM messages WHERE sent_by = 1