postgresql compare column value from first row only
You could it much more simply:

SELECT end_datetime &gt; now() AS result 
FROM history 
ORDER BY start_datetime DESC 
LIMIT 1 ;


The query is similar to your subquery, it returns only one row, the latest start_datetime. The end_datetime &gt; now() in the select list is a boolean expression so it retuns either TRUE or FALSE, depending on the value of end_datetime in that row. We don't need to join this result set to the table because all the information we need is there, in the one row.

You could modify the select list, to include other columns, too, or all the columns if you need them:

SELECT end_datetime &gt; now() AS result,
       start_datatime,
       end_datetime
...


For efficiency, you need an index on (start_datetime). Your query would be efficient, too, despite the unneeded self-join.