Lets say this is the database structure:

SELECT * FROM `pms` where id_to = 1 or id_from = 1
This would return all the messages that he has recived or sent,
So how can I retrieve the last message from each conversation that the user 1 may have?
PD: I call it conversation when there is one or more messages between two users
-edit-
So given this database content:

We want to get id 4 and 6
This assumes
idis an auto-increment column:Assuming you have
id_fromandid_toindexed, this variation will most likely perform better because MySQL doesn’t know what to do with an OR:Here’s how to get the messages for those ids: