For a messages
table with the following structure
id, sender_id, receiver_id, text
I want to build a list of distinct users (ordered by message id) who have either sent a message to or received one from the current session holder. The list should contain a user only once.
A query such as:
"SELECT * FROM messages WHERE sender_id = '$sess_id' OR receiver_id = '$sess_id'";
yields duplicates i.e. multiple rows with the same user. Does one necessarily have to do the filtering after the SQL query or is there an SQL query that will yield the desired unique list?
Thanks!