Atticus
Atticus

Reputation: 1632

hql select from select problem

I would like to count the number of groups of a group by statement. In SQL that would look like:

select count(*) from (select count(*) from MyTable t group by t.col1, t.col2) g

But in HQL it seems I can not do a select in a select as I did in the previous sql. I guess the problem is that Hibernate does not support subquery in the from clause. Is there any way to do this in hql?

Upvotes: 0

Views: 883

Answers (1)

Atticus
Atticus

Reputation: 1632

Well, I have finally run the following query in hql:

select count(*) from MyTable t group by t.col1, t.col2

and then used the size of the returned list, which is exactly the number of groups.

Upvotes: 1

Related Questions