0

I hope everyone of you will be in good health.

I am working on a Chatting Application. Its a PHP/MySQL based application.

I have the following table named: messages .......

enter image description here

For Getting Recent Conversation, just like we see in Social media websites. I have written the below query for current logged-in user having auto_id = 1.

SELECT * FROM (
    SELECT * FROM (
         (SELECT auto_id, from_user_auto_id, to_user_auto_id, message, added_on FROM messages WHERE from_user_auto_id = '1')
       UNION
          (SELECT auto_id, from_user_auto_id, to_user_auto_id, message, added_on FROM messages WHERE to_user_auto_id = '1')
          ) as t
       ORDER BY added_on DESC
    ) as t2
GROUP BY to_user_auto_id, from_user_auto_id ORDER BY added_on DESC

This query returns me the below results:

enter image description here

Its not working as it should return me the result. Please help.

SQL Fiddle: http://sqlfiddle.com/#!9/166a19/4

The link of the question that someone suggest is not even close to this question. Please Re-check.

John Doe
  • 1,353
  • 1
  • 2
  • 12

0 Answers0