Hello I have a table messages and I want to display a conversation-style inbox (just like gmail) conversation order by date and grouped by user

table messages

* from\_user\_id
* to\_user\_id
* message
* read
* from\_user\_deleted
* to\_user\_deleted

users table

* id
* username

this is my SQL query to get all messages received or sent by me (user: 1)

UPDATED QUERY!

```
    SELECT 
        account_id,
        accounts.username,
        status,
        content
    FROM
        ((SELECT
                id,
                to_id AS account_id,
                content,
                status
        FROM messages
        WHERE from_id = 1 ORDER BY id DESC)
      UNION
        (SELECT
                id,
                from_id AS account_id,
                content,
                status
        FROM messages
        WHERE to_id = 1 ORDER BY id DESC)
      ) AS messages, accounts 
      WHERE accounts.id = account_id AND accounts.deleted = 0
    GROUP BY 
        account_id
    ORDER BY messages.id DESC

```

Now I´m getting more accurate results. how can i make sure that the query is returning the LAST message sent for each conversation? thanks!