Suppose there are two tables `chat` and `users`. `chat` have four columns id, sender, receiver and message and `users` have two columns id and name.
|1||1||2||Hi, how are you?|
SELECT u1.name as sender, u2.name as receiver, c.message FROM `chat` as c
LEFT JOIN `users` as u1 ON c.sender = u1.id
LEFT JOIN `users` as u2 ON c.receiver = u2.id
In the result you will get sender name, receiver name and message/chat that taken place between them.