3

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)
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Jay
  • 19,649
  • 38
  • 121
  • 184

2 Answers2

8

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
Jay
  • 19,649
  • 38
  • 121
  • 184
3

From this link, there's a explanation of the general structure of a JPA SELECT Query:

SELECT ... FROM ...
[WHERE ...]
[GROUP BY ... [HAVING ...]]
[ORDER BY ...]
Cacovsky
  • 2,536
  • 3
  • 23
  • 27