-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL Query to find Duplicate rows in a table??
PostPosted: Wed Jun 02, 2010 4:06 pm 
Newbie

Joined: Thu Nov 27, 2008 11:05 pm
Posts: 9
I am trying to convert the following SQL query to an HQL query, but cannot figure this out. This query bascially finds all the duplicate rows in a Contacts table according to company, firstname, and lastname. The simple "having" and "groupBy" query that I've seen on the web won't work since I need every row that is a duplicate. My sql is below. Is this possible in HQL?

For this HQL there are only two classes that apply: Contact and Team. (Team -> Contact : One -> Many)

Code:
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 c2.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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.