Ver originalCREATE TEMPORARY TABLE tmp select cedula,max(fecha)as fecha,max(id) as tt, tipi from `data` group by `cedula`select a.cedula,b.tt,b.fecha,b.tipi,max(a.id),max(a.fecha),max(a.tipi) as tt1from data a, tmp bwhere a.cedula=b.cedula and a.id <> ttgroup by a.cedula,b.tt