I am trying to write the following SQL query using the JPA Criteria API
SELECT * FROM Table1 a
WHERE (a.category, a.priority) IN (
SELECT a1.category, max(a1.priority) FROM Table1 a1 GROUP BY a1.category
)
Functionally, the query select the element of Table1 with the highest priority for each category.
categoryPriority = // defines the pair category/priority
mySubQuery = // defines the subquery
query.where(categoryPriority.in(mySubQuery)
This is schematically what I am looking for.
Defining the subquery is not a problem since it is well documented.
But I cannot find a way to define the couple (a.category, a.priority).