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.  [ 3 posts ] 
Author Message
 Post subject: Not sure how to write this query...
PostPosted: Fri Mar 27, 2009 4:54 am 
Newbie

Joined: Tue Jun 20, 2006 8:11 am
Posts: 7
Hi all, Using Spring / JPA & Hibernate, with my DAOS using the getJPATemplate() method of querying my db I'm stuck designing a particular query..

What I need to do is query to create a list of objects where there is more than one occurance of an element over particular dates.. Ill show you a class structure to describe this..


class A {
String name;
Date theDate;
... lots of other fields
}

so what I need is to create a list containing just the name and theDate fields from object A where the name occurs more than once .. e.g. say this is my table contents:

Name TheDate

dave 1/1/1
dave 2/1/1
john 1/1/1
frank 1/3/1


if that was my data set i'm query against I want my resulting list to contain the two daves... because it occurs on more than one date...

I hope this makes sense.. I'm not sure how to do this kind of query with JPA & Hibernate.. any help appreciated..

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 28, 2009 9:21 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Maybe
Code:
select name, thedate from A a1 where 1 < (select count(*) from A a2 where a1.name = a2.name )

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 30, 2009 12:44 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Please go with mmerder suggestion.. In practice I have used this query:-

select a1.name, a1.thedate from A a1, A a2
where a1.name = a2.name and a1.date != a2.date

Hope this helps,
Latha.


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

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.