select distinct table1.ime from table1, table2 where table1.id=table2.table1_id order by table1.prilepljena asc, table2.datum desc;