Help with HQL Query (find duplicates)
Posted
by BRhodes
on Stack Overflow
See other posts from Stack Overflow
or by BRhodes
Published on 2010-06-02T19:50:40Z
Indexed on
2010/06/02
19:54 UTC
Read the original article
Hit count: 214
I am trying to convert this native sql into an HQL query. Basically it returns all the contacts that are duplicates (by company, firstname, and lastname). The query below works great, but performing a joined subselect seems impossible in HQL is it not?!
Select c.* from contact c
join
(
Select c2.* from contact c2
group by c2.company, c2.firstname, c2.lastname, c2.teamId
having count(c2.contactId)>1 and teamId=1
) dupes
on c.company=dupes.company
and c.teamId=1
and c.firstname=dupes.firstname
and c.lastname=dupes.lastname
order by c.company, c.firstname, c.lastname
© Stack Overflow or respective owner