SELECT DISTINCT ON (observation_id) * FROM observation LEFT JOIN soilobs USING (observation_id) ORDER BY observation_id, soilobs_id