1
Does anyone know how I could list each user’s last message?
I was able to do that, but it lists the last message from just one user, and I wanted it to list everyone who sent a message to the user in question (code 3).
SELECT m1.codigo,
m1.codigo_remetente,
usuario.url,
m1.descricao,
m1.data,
m1.visualizado,
usuario.nome,
usuario.sobrenome
FROM mensagens m1
JOIN usuario ON m1.codigo_remetente = usuario.codigo
AND m1.codigo_destinatario = 3
AND data = (SELECT MAX(data)
FROM mensagens m2
WHERE m2.codigo_remetente = m1.codigo_remetente)
ORDER BY data DESC
Table User: code, name, surname, url.
Table Message: code, sender code, destination code, description, date
What is the structure of the tables
mensagem
andusuario
in the database?– Woss
I edited the post with the columns of the tables.
– Diego Vieira
Table message defines the many-to-many relationship between two users? Can you explain the problem better? How would this "list everyone who sent a message to the user"?
– Woss