-->
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: max() in subselect with Hibernate and Derby/MySQL
PostPosted: Tue Jan 08, 2008 5:24 pm 
Newbie

Joined: Sat Jan 05, 2008 12:29 pm
Posts: 3
Location: Bordeaux, France
Hi,

I'm having trouble with how to apply the max() function to the result of a select. Right now my code looks like this:

session.beginTransaction();

Query hqlQuery = session
.createQuery("select m.nom, sum(s.quantite)"

+ " from Puzzle p, Magasin m, Stock s"
+ " where p.pieces between "+min+" and "+max

+ " and p.id = s.idJouet and m.id = s.idMagasin"

+ " group by m.nom");

That code works just fine. The thing is, I need to display only the m.nom of sum(s.quantite) biggest value (using max() I think). But I don't know how to do this.

I'm using Eclipse 3.2, Hibernate 3.3 and either Derby or MySQL (I think Derby doesn't support subselect btw). Any example code on how to solve this would be GREATLY appreciated.


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.