There are two ways (not mutually exclusive) to improve query performance. First, you could re-write the correlated subquery into a subquery with an aggregate:
FROM menmembers AS m
LEFT JOIN (
SELECT cod_usr, MAX(datetr) AS LastLogin
GROUP BY cod_usr
) AS t ON m.memb_id=t.cod_usr;
Second, you can add a proper index to
CREATE /* UNIQUE? */ INDEX IX_trank_LastLogin ON trank (cod_usr, datetr);
Simply for query performance, I would consider sorting the datetr column DESC in this index, although that may not be optimal for INSERTs into the table. Alternatively, you could just INCLUDE the datetr column:
CREATE INDEX IX_trank_LastLogin ON trank (cod_usr) INCLUDE (datetr);
Obviously, you should have an index on
menmembers.memb_id as well for this to work properly, but I'm guessing that's already taken care of.
I've written this code for SQL Server, but since you haven't tagged your dbms, I can't be sure it'll work on your setup.