I have the following SELECT
to select data from a table ( chat
) on a chat system:
SELECT * FROM (SELECT * FROM chat WHERE id_chat = '$chat_id' ORDER BY id DESC LIMIT 10) S WHERE id_chat = '$chat_id' ORDER BY id ASC LIMIT 10
The same query returns the last ten messages to display them in descending order.
In this table ( chat
), there is a usuario
column where it represents the id
of the user who sent the message.
I would like, from the id
of the user who sent the message, to be able to return the data of that user (table usuarios
).
Example of table usuarios
:
id | nome | foto
1 | Lucas | perfil.jpg
What is the best way to do this using the above query? LEFT JOIN
? INNER JOIN
? And how to do it?