select t1.* from tabla1 t1 where t1.codigo not in (select codigo_relacion from tabla2) and t1.fecha = (select max(fecha) from tabla2)