Hi,
I have the following SELECT which pulls out messages which are sent to users within a website.
"SELECT (hussaini_messages.type_id) AS IID, " +
"(hussaini_messages.message_id) AS MID, " +
"(hussaini_messages.recipient_id) AS RID, " +
"(hussaini_messages.sender_id) AS SID, " +
"(hussaini_messages.subject) AS Subject, " +
"(hussaini_messages.message) AS Message, " +
"(hussaini_messages.thread_id) AS TID, " +
"(hussaini_messages.date_added) AS MSGDATE, " +
"(hussaini_users.user_id) AS UID, " +
"(hussaini_users.fname) AS Fname, " +
"(hussaini_users.sname) AS Sname, " +
"(hussaini_users.avatar) AS Avatar " +
"FROM hussaini_messages LEFT OUTER JOIN hussaini_users ON " +
"hussaini_messages.sender_id = hussaini_users.user_id WHERE hussaini_messages.recipient_id = @recipient_id OR hussaini_messages.sender_id = @recipient_id " +
"ORDER BY hussaini_messages.date_added DESC";
Now the problem is that in my table hussaini_messages, i have multiple rows which relate to the same message. What this SELECT does is pull out every one.
I think i need to do something where i only pull out the 1. For example if i have 3 rows. 2 with message id of 1 and 1 with message id of 2. I have the problem becuase the message that links to message_id 2 is pulled out twice and displayed twice. So how can i pull out the one message?
I think its a GROUP BY but i dont know how to do it…
Regards
Billy