@sibertJan 26.2021 — #``<i> </i>SELECT id FROM test WHERE entrydate=(SELECT min(entrydate) FROM test)<i> </i>`` https://www.db-fiddle.com/f/f8nZn5LQfbmKxAdxX2fdej/59
@NogDogJan 26.2021 — #I'm not sure you actually gain much by doing it in a single query, so I might be tempted to just do it as two separate queries. But _maybe_... <i> </i>select first.id as first_id, first.entryDate as first_date, last.id as last_id, last.entryDate as last_date from (select id, entryDate from entries order by entryDate limit 1) as first left join (select id, entryDate from entries order by entryDate desc limit 1) as last
But then you're really just wrapping 2 queries inside of 1 query, so it may be no less efficient to just make those 2 queries separately (or so minimally different that keeping the code simple is worth it).
PS: Not sure if that join might have to have an ON clause, in which case: <i> </i>left join (select id, entryDate from entries order by entryDate desc limit 1) as last on true
@sibertJan 26.2021 — #``<i> </i>SELECT (SELECT id FROM test WHERE entrydate=(SELECT min(entrydate) FROM test)) min, (SELECT id FROM test WHERE entrydate=(SELECT max(entrydate) FROM test)) max<i> </i>`` https://www.db-fiddle.com/f/f8nZn5LQfbmKxAdxX2fdej/61