select distinct on inner join