-->
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 for a newbie - sos
PostPosted: Fri Aug 04, 2006 6:34 pm 
Newbie

Joined: Wed Mar 22, 2006 6:30 am
Posts: 9
Hibernate version: 2

can you use hsql to "select" and "group by" without specifying all of the fields in the select and the group by? i have to retrieve 280 fields from three tables/objects (mapped many-to-one, many-to-one, many-to-one).... specifying all the fields explicitly, i get a huge sql statement which is bombing in db2...

e.g.:

select obj1.obj2.obj3.lotsoffields (...), obj1.obj2.lotsoffields (...) from Object1 obj1
group by obj1.obj2.obj3.lotsoffields (...), obj1.obj2.lotsoffields (...)

i tried something like:
select obj1.obj2.obj3, obj1.obj2 from Object1 obj1
group by obj1.obj2.obj3, obj1.obj2

...but using show_sql=true i get only the PK's in the group by, and all the fields in the select -- sql error.

thank you!

tom


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 10:54 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No. If there's a group by clause, all pure columns returned in the result set must appear in the group by. This is an SQL restriction. Think about it like this: if you had a table containing fruit, and you wanted to group by colour, you must obviously only get a single row returned for "red": that's what group by is for. So how do you return all the names of all red fruit in the single name column? You can't. You could return the longest name, or the first name, but not all names.

Perhaps you don't want group by? In the above example, if you wanted a query to return the name of all red group, you'd use where colour = "red", not group by colour.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 11:41 pm 
Newbie

Joined: Wed Mar 22, 2006 6:30 am
Posts: 9
thanks, funny, i did not now that hql has "distinct" - all i needed was to use that key word...

tom


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.