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: HQL Select statement in From clause
PostPosted: Tue May 26, 2009 10:26 am 
Newbie

Joined: Tue May 19, 2009 4:44 pm
Posts: 1
After too much trial and error and reading all the HQL material I could find I was hoping someone might have experience with the following and point me in the right direction.

I currently use the following SQL statement to retrieve projected data associated with only the highest versioned Name, Version pairs listed in a table:
Code:
SELECT r.rule_id, r.rule_name, r.version
FROM rule r, (SELECT MAX(version) AS maxver, name FROM rule GROUP BY name) maxresults
WHERE r.name = maxresults.name AND r.version = maxresults.maxver

The above statement returns results similar to the following:

id | Name | Version
--------------------
a4 | Name1 | 4 (where the table contains version #s 1 - version # listed)
g3 | Name2 | 1
s2 | Name3 | 8

Is it possible to use a HQL select statement in a From clause to achieve similar results as with SQL?
Is it possible to use HQL to retrieve an entity object (as opposed to using projection to retrieve only id, name, version) as result from an HQL version of the SQL Query?

Any help/suggestions are greatly appreciated.

jason


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.