Search code examples
javaormjpajpql

Using group by and having in a JPA query


How would you do the following using the JPA query language?

select * from person where email in
(select email from person group by email having count(email)>1)

Solution

  • Finally found a solution:

    select p from Person p
    where p.email in (
        select q.email
        from Person q
        group by q.email having count(q.email)>1)
    order by p.email, p.id