-->
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: Is it possible to sort before grouping?
PostPosted: Mon Oct 11, 2010 10:33 am 
Newbie

Joined: Wed Jan 09, 2008 10:04 am
Posts: 2
I am trying to sort using "order by" _before_ grouping with "group by" but it does not seem to work. The grouping works fine but the ordering is ignored. I am using Hibernate 3.2.6.

The hibernate query is of the form:

"from Customer where id in (select id from Customer order by id desc) group by companyName,siteName"

The part in parentheses does return results order by desc id as desired. However, once the grouping occurs, the lowest id is the one that is in the result for each group.

What I am trying to accomplish is to get a list of all entries in Customer to be grouped by company name, and only the one with the highest id to be reported in the result.

I would also prefer to avoid having to do extra work on the resulting list or collection in Java.

Any tip would be highly appreciated.
Thanks.

PS: this is feasible in MySQL, but I would like a HQL query.


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.