-->
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: group by with HQL
PostPosted: Wed Feb 04, 2009 7:53 pm 
Newbie

Joined: Wed Aug 01, 2007 6:08 pm
Posts: 13
I am trying to retrieve latest version of rows and following SQL works for me

select id, max(version), marketplace, package from mytable where marketplace = 'XXX' and package = 'YYY' group by marketplace, package order by version desc

But I am unable to get equivalent HQL working, e.g.
from mytable m1 where m1.version = (select max(m2.version) from mytable m2 where m2.marketplace = 'XXX' and m2.package = 'YYY' and m1.id = m2.id) group by m1.marketplace, m1.package order by m1.version desc


Though this query compiles and runs but returns wrong row. Any idea? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 1:21 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
why r u trying to get object list friend,
as u r need of only three rows u may try this hql ..

select max(m2.version) from mytable m2 where m2.marketplace = 'XXX' and m2.package = 'YYY' and m1.id = m2.id group by m1.marketplace, m1.package order by m1.version desc

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 1:08 pm 
Newbie

Joined: Wed Aug 01, 2007 6:08 pm
Posts: 13
I am saving objects with different versions and am trying to get the latest version of the object. So I need to get full object not just version number.


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.