views:

83

answers:

1

I want to retrieve unique data froma table based on latest time stamp.

So If I have a table like this

guid  6   1/7/2010 9:55:29 PM
guid  6   1/5/2010 2:59:29 PM
guid  6   1/7/2010 2:55:29 PM

I need to write a query where I can query with no 6 and with latest timestamp in the same table. So it should return me :

guid  6   1/7/2010 9:55:29 PM
A: 

I can't test this at the moment, but I think the HQL would look something like this:

from Item as i
where i.Number = 6
order by i.Date desc

Then when you create your Query object in code, you'll want to call query.setMaxResults(1);

As far as I know, there's no "select top" (or equivalent) in HQL.

Andy White
Ah, I see. I misread the question. I think `query.setMaxResults(1);` is the proper way to do it then.
David Hogue