-->
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: max value of column from multiple tables
PostPosted: Wed Aug 24, 2011 5:26 pm 
Newbie

Joined: Wed Aug 24, 2011 5:19 pm
Posts: 4
Is there any way i could use HQL to get the maximum value of columns from multiple tables..

I have a column called modifiedDate in 2 different tables, i would like get max of this, is it possible??

I tried like this..
SELECT greatest(obj1.modifiedDate, obj2.modifiedDate) FROM Object1 AS obj1, Object2 AS obj2 WHERE obj1.id = :id and obj2.object1Id = :id

It didnot work as greatest function is not part of the hibernate??

Any ideas please?


Top
 Profile  
 
 Post subject: Re: max value of column from multiple tables
PostPosted: Thu Aug 25, 2011 2:51 pm 
Newbie

Joined: Wed Aug 24, 2011 5:19 pm
Posts: 4
I tried like this to get the list of objects..but this is working only when there is data present in 2 tables. Even if one table has null value then it is returning null because of the cross join.
SELECT new List(obj1.modifiedDate, obj2.modifiedDate) FROM Object1 AS obj1, Object2 AS obj2 WHERE obj1.id = :id and obj2.object1Id = :id

is there any alternate solution? or using using loader on property??


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.