-->
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: Which is the best strategy for retrieving the smallest c_id
PostPosted: Mon Mar 26, 2007 12:16 pm 
Newbie

Joined: Mon Mar 26, 2007 10:36 am
Posts: 3
Hello,

I'm trying to implement a FIFO process. I need to always extract the row with the smallest c_id value. My first guess was to use a sql query with a subquery.

select * from table where table.id=( select min(table.id) );

I have searched the forums, but I have not found anything at all.

Thanks,

Sid


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 1:50 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
hibernate supports sub queries if your db does

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 2:27 pm 
Newbie

Joined: Mon Mar 26, 2007 10:36 am
Posts: 3
kochcp wrote:
hibernate supports sub queries if your db does


Thanks for the reply. However, my app will work with different databases. And because not all of them support subqueries, we want to avoid them.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 2:50 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
you could:

select * from Table order by id asc

and then use Query.setMaxResults(1) to get only the first row.

_________________
nathan


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.