-->
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: From SQL to HQL/Criteria
PostPosted: Wed Jan 28, 2009 3:30 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
Hello all

I have a "quite simple" SQL query that I would like to propose both as HQL AND Criteria
accessible
Tried several things without any success, looked into the forums without any more luck and googled for more infos on subqueries without being able to find anything which could lead to working code

Could anyone help please
Many thanks

Here is the "beast" which is supposed to return the latest demo and test files in a given directory in one shot

Code:
select db_id,shortname,fullname,file_date from
    (select db_id,shortname,fullname,file_date from Files
            where folder_id=1 and shortname in ('demo','test')
            order by shortname,file_date desc)
    as subquery
group by name


which can also be rewritten as

Code:
select db_id,shortname,fullname,file_date from
    (select name as xname,max(file_date) as last from Files
             where folder_id=1 and name in ('demo','test')
            group by name)
    as subquery inner join Files as result
    where subquery.xname = result.shortname and subquery.last = result.file_date


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.