I wrote the following query for MySQL:
SELECT subquery.t1_column1, subquery.t2_id, MAX(subquery.val) FROM ( SELECT t1.column1 as t1_column1, t1.id_t2 AS t2_id, count(1) AS val FROM table1 t1 INNER JOIN table2 t2 ON t2.id = t1.id_t2 GROUP BY t1.id_t2 ) subquery GROUP BY t1_column1
And I would like to translate it into JPA (JPQL query or criteria).
I don't know how to do this maximal (countable) thing, and JPA doesn't seem to like SELECT FROM SELECT ...
If someone has an idea other than their own requests (I will do it now), it would be great.
source share