-->
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: SQL help on HQL with group by/ max function
PostPosted: Mon Nov 02, 2009 6:46 am 
Newbie

Joined: Mon Nov 02, 2009 6:36 am
Posts: 2
Hi,

Can someone help me on this problem i have...

I'm using hibernate...and have a table named case_score_t with these columns:
id, case_id, user_id, score, created_date

I am interested in picking the rows with the greatest created_date, for a certain user_id.

I have this SQL currently
"SELECT cs FROM CaseScore cs WHERE cs.user.id = ? GROUP BY cs.c.id ORDER BY cs.created DESC"
but this will not provide me the correct result!!!

This SQL with give me the correct result:
SELECT *, max(created) FROM case_score_t cs WHERE cs.user_id = 1449 GROUP BY cs.case_id;

The problem is that i have is that i get an extra column, the max(created) column back.

Is there anyway to do the same query(maybe with criteria or subselect's...), without getting the extra
max(created) column, but still getting the rows with the greatest created date, for a certain user... ?

Because i want to be able to do a SELECT cs ... rather than picking the max(created) as a separate
column.

Any help will be appreciated...

Best Regards
Cemils


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.