SELECT max(actor_id) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id), max(first_name) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id), max(last_name) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id), max(c) KEEP (DENSE_RANK FIRST ORDER BY c DESC, actor_id) FROM ( SELECT actor_id, first_name, last_name, count(film_id) c FROM actor LEFT JOIN film_actor USING (actor_id) GROUP BY actor_id, first_name, last_name ) t; SELECT FIRST(actor_id ORDER BY c DESC, actor_id), FIRST(first_name ORDER BY c DESC, actor_id), FIRST(last_name ORDER BY c DESC, actor_id), FIRST(c ORDER BY c DESC, actor_id) FROM (...) t; So, we’re getting the FIRST value of an expression per group when we order the group contents by the ORDER BY clause.