Getting top 1 per group values is a bit tricky in SQL in general. This post explains how to do this with Oracle when multiple values per group are requested| Java, SQL and jOOQ.