-->
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: HQL: order by clause with aggregate function
PostPosted: Fri Feb 25, 2005 9:48 am 
Newbie

Joined: Fri Feb 25, 2005 9:37 am
Posts: 3
hello

I was wondering why the folling query gives crashes with the message "Invalid use of group function" (MySQL)

When I order the query by c.ID everything works fine, but I can't order it by an aggregated field.

Does anyone know why and how it should work???
The query already looks like the examples in the Hibernate documentation...


select c, max(log.date), count(log.ID)
from LoginLog log, Customer c, User u
WHERE ...
group by c.ID
order by max(log.date)

Thanks for help
Lars


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 10:41 am 
Newbie

Joined: Mon Jan 17, 2005 9:23 am
Posts: 15
maybe try setting an alias, like:

select c, max(log.date) as maxDate, count(log.ID) as countID
from LoginLog log, Customer c, User u
WHERE ...
group by c.ID
order by maxDate

Just guessing. For better debugging I suggest you set show_sql=true and look at the SQL it generates.


Top
 Profile  
 
 Post subject: Re: HQL: order by clause with aggregate function
PostPosted: Fri Feb 25, 2005 10:56 am 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
sneaker wrote:
hello

I was wondering why the folling query gives crashes with the message "Invalid use of group function" (MySQL)


Old versions of MySQL don't support ordering by aggregate functions' result.


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.