0
I need to do an SQL query where returns the last messages exchanged between users (my account for example) and who I talked to... regardless of whether the last conversation was sent or received.
The code I am using behind the sent and received in the case repeating the user, I would like to know how I do not repeat group only my last conversation with whom I talked independently if the message was sent or received.
SELECT distinct * FROM mensagens inner join usuarios on de = id_user where para LIKE '$sessao'
union SELECT distinct * FROM mensagens inner join usuarios on para = id_user where de LIKE '$sessao'
group by id_user order by id asc
Table messages:
id - de - para - mensagem
Table users:
id_user - nome
In
$sessao
receives its own ID?– Jader A. Wagner
Jonatan, it’s nice to indent SQL like @Jader does in the answer below, it’s much easier to understand what is happening.
– brasofilo