-->
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.  [ 2 posts ] 
Author Message
 Post subject: hql: group by and alias
PostPosted: Thu May 03, 2007 8:11 am 
Newbie

Joined: Fri Mar 16, 2007 6:04 am
Posts: 14
Hi,

I was wondering if there is a way to use alias in the GROUP BY clause.

For example :

Code:
SELECT m.id AS foo,
  COUNT(m)
  FROM Member m
  GROUP BY foo


throws an SQLGrammarException. If I replace the last line with

Code:
GROUP BY m.id


works just fine. If instead of m.id had a complicate function
eg. LOWER(SUBSTRING(m.surname, 1, 1)) I wouldn't want to repeat that in the GROUP BY clause. Is there any other way?

Thanks,
akz


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 8:43 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Well, you can't do that in SQL, so I wouldn't expect it to work in HQL. Also, from the docs:

Reference Docs wrote:
Note that neither the group by clause nor the order by clause may contain arithmetic expressions.


Note, however, that you can use aliases in Criteria restrictions and ordering.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.