I have a table "messages" that you can see the following image:
from this table my id as user is 2. Sometimes I am sender, sometimes I am receiver.
I need a query that returns only the last message I exchange from each user. No matter if I sent it, or I received it. I am not sure if I should use distinct here. I don't really know how to use it.
To be more understood, in the above table for example should return:
row with id=4 (the last message I had with user 4)
row with id=6 (the last message I had with user 1)
row with id=7 (the last message I had with user 3)
row with id=5 (the last message I had with user 7)
row with id=19 (the last message I had with user 15)