-->
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 - how create select with join from subselect
PostPosted: Thu Nov 18, 2010 8:21 am 
Newbie

Joined: Thu Nov 18, 2010 8:02 am
Posts: 1
Hi,
I'm unable to create join from select in HQL (Question are on botton). I have such situation:
Code:
Class Record {
   Date day;
   int value_index;
   long value;
}

And folowing data (number represets unique record of column type):
day,value_index,value
Code:
1, 0, 20
1, 1, 22
1, 2, 23
2, 1, 10
2, 2, 11
3, 1, 11

For each day i have 1..n records, they are indexed with value_index (incremental). I want fetch from DB for each day this records that have max(value_index) for this day:
Requesting result:
Code:
1,2,23
2,2,11
3,1,11

In SQL i will do this with join from subselect:

Code:
select * from Record r1
   join (select day, max(value_index) from Record group by day) r2
   on r1.day = r2.day

In HQL - this concept does't work:
Code:
select r1 from Record r1
   join (select r.day, max(r.value_index) from Record  r group by r.day) r2
   on r1.day = r2.day

--- QUESTION----
Is in HQL some way to receive such result?
Are joins from subselect in HQL unsuported?
Where can i found exact syntax of HQL (Something like for SQL:
Code:
SELECT <column list>             
FROM <left joined table>         
[INNER] JOIN <right joined table>
ON <join condition>
)?


Top
 Profile  
 
 Post subject: Re: HQL - how create select with join from subselect
PostPosted: Fri Nov 26, 2010 1:37 pm 
Newbie

Joined: Fri Nov 26, 2010 1:21 pm
Posts: 1
Does anyone have a any clue about this? I'm interested in the answer too, because I'm having the same situation over here.


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.