Lets say this is the database structure:
SELECT * FROM `pms` where
select pms.* from pms
inner join
(select max(fecha) as max_fecha,
if(id_to
Also if id_to and id_from in your table are small enough to prevent overflow in statement (id_to+id_from) here is the simple query:
select pms.* from pms
inner join
(select max(fecha) as max_fecha, id_to+id_from as sum_id
from pms where id_to = 1 or id_from = 1
group by id_to+id_from) t
on ((pms.id_to+pms.id_from)=t.sum_id)
and (pms.fecha=t.max_fecha)
where pms.id_to = 1 or pms.id_from = 1