Group private messaging system
I am coding for a private messaging system that works great. I need to write a SQL query for group messages and this message should only appear once. In short, I want to "view the conversation" just like I do on Facebook, only showing the last message, either sent or received. Script in the backend is PHP in a private messaging system.
I have attached a screenshot:
Here is the attached query that I am using.
Testing demo is downloaded at this address: http://developers89.byethost14.com/messages/
+3
source to share
1 answer
SELECT *
FROM conversation
WHERE (LEAST(sender_ID, receiverID), GREATEST(sender_ID, receiverID), date)
IN
(
SELECT LEAST(sender_ID, receiverID) x,
GREATEST(sende_ID, receiverID) y,
MAX(date) max_date
FROM conversation
GROUP BY x, y
)
AND '$uid' IN (sender_ID, receiverID)
// AND other conditions if you have .......
// ORDER BY .....
// LIMIT ........
+6
source to share