I have a history of conversations that are registered in the table sql "conversation" and I want to pick who was the last person who inserted a message in the conversation to know if it was the user who wrote last or if it was the admin (id 28) .
Is there a way to do a SELECT with a rule to know which last date or last id?
id|idusuario|idconversa| mensagem |data
1 | 700 | 2 | mensagem 1 |2018-05-24 10:20:21
2 | 28 | 2 | mensagem 2 |2018-05-24 10:30:21
I've set up the following:
SELECT idusuario
FROM conversa
GROUP BY idconversa
Then when I return the last id that inserted the conversation I will make an if to say if it was the admin or the user (this part is already ok);