-->
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.  [ 3 posts ] 
Author Message
 Post subject: Limiting number of results in a subselect? (ex:SELECT TOP 1)
PostPosted: Sun Apr 01, 2007 4:10 pm 
Newbie

Joined: Fri Sep 16, 2005 2:20 pm
Posts: 4
Hibernate version: NHibernate 1.0.4.0

(Other items are irrelevant)

How can I limit the number of records returned in an HQL subselect?

EXAMPLE (no this is not a valid hql statement, I am trying to figure out how I would code this in a valid way)


SELECT a.name, b.name
FROM Eg.One a
LEFT OUTER JOIN Eg.Two b
WHERE b.createdate = (SELECT TOP 1 b2.createdate FROM Eg.Two b2 ORDER BY b2.createdate DESC)


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:48 am 
Newbie

Joined: Thu May 03, 2007 6:02 am
Posts: 3
You can use the following property :

IQuery query = TransactionManager.GetHibernateSession().CreateQuery( query );
query.SetMaxResults( 1 );


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 11:25 pm 
Newbie

Joined: Fri Sep 16, 2005 2:20 pm
Posts: 4
Actually, that wouldn't work because the limit would be applied to the top level query, not the subquery.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.