Prova.

SELECT * FROM tabella T1
WHERE id = (SELECT MAX(T2.id) FROM tabella T2 where T1.filename = T2.filename)
group by filename