D
D
Daniil Sukhikh2021-12-12 19:46:18
MySQL
Daniil Sukhikh, 2021-12-12 19:46:18

How to get latest message via join?

I have a query with which I get the friends of a certain user. But I also want to get the last message between these users, but when I try to get messages via inner join I get all the messages. How to get only the latest?
Current request:

SELECT * FROM `friends` INNER JOIN `users` ON users.id = friends.`id_one` OR users.id = friends.`id_two` WHERE (friends.`id_one` = 1 OR friends.`id_two` = 1) AND `users`.id != 1 AND friends.status = 'friend'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question