Column must appear in the GROUP BY clause or be used in an aggregate function when using CASE statement in ORDER BY clause
If all events have the same from_date:

SELECT event_id
FROM   date_ranges
WHERE  through_date &gt;= current_date
GROUP  BY event_id, from_date  --  add it to GROUP BY
ORDER  BY from_date &gt; current_date; -- simplified expression (assuming NOT NULL)


But then the column should be in the event table once per event.

If not, your sort order is ambiguous. I would start by asking how the same event can have different date ranges?

Your setup is broken either way.