-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL version of this one-line SQL statement
PostPosted: Wed Jul 30, 2008 9:46 pm 
Newbie

Joined: Wed Jul 30, 2008 9:25 pm
Posts: 3
Please can someone here help? This is all I need converted from SQL to HQL:

SELECT TOP 1 [fieldName] FROM [tableName] ORDER BY [fieldName] DESC

I have actually tried to figure it out on my own but am getting stuck on how to implement "SELECT TOP" and "DESC" in HQL.

It returns the largest number of a certain field within a table, and this one-line of code is all that stands between me and finishing my project (which I needed to have finished yesterday).

Thank you kindly in advance if someone can help!!

-Dave


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 11:33 pm 
Newbie

Joined: Wed Jul 30, 2008 9:25 pm
Posts: 3
Ooops ... the SQL statement for which I need an HQL equivalent is actually this:

SELECT MAX( [fieldName] ) FROM [tableName]

Pray tell, how would I do this in HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 2:09 am 
Newbie

Joined: Wed Jul 30, 2008 7:48 am
Posts: 10
Location: NOIDA
try to execute hql like " from [Object] order by [column] desc". and first row will give you the max of your desired column.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 3:46 am 
Newbie

Joined: Wed Jul 30, 2008 9:25 pm
Posts: 3
Thanks it looks like that will work ... although I just discovered an even easier solution:

select max([column]) from [Object]

Thanks!


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