Frage

I've a JPQL like this:

SELECT T0.id, T0.info, COUNT(T0.entry) AS count_entry FROM myObject AS T0 WHERE T0.someValue = 1 GROUP BY T0.id, T0.info

I want to get the first 100 results of this. The problem I have is, that if I declare maxResults-Parameter, the ROWNUM <= 100 is added to the where-clause. The where clause is evaluated before the grouping takes place - so I do not get 100 results in resultlist, I get less because of the grouping.

Any ideas to limit the result set AFTER grouping?

War es hilfreich?

Lösung

I found the solution. If you add an order-by clause, the problem is solved and the limitation of the number of results is in an extra query around the other query.

Query working as expected:

SELECT T0.id, T0.info, COUNT(T0.entry) AS count_entry FROM myObject AS T0 WHERE T0.someValue = 1 GROUP BY T0.id, T0.info ORDER BY T0.id
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top