Click to See Complete Forum and Search --> : sql querry question...


Avenger001
April 21st, 2003, 02:27 PM
Is there a way to retrieve just the last entry in the table thru an sql querry.

Ex.
In my table, right now, I have 665 entries, and I would like to retrieve just the 665th element.

If it makes any difference, i'm going to be using this querry in my c# application.

So far, my querry is :
"SELECT * FROM myTable ORDER BY uniqueID DESC"

And with that querry, the 1st element would be the 665th element, then I would just take this element with a bite of coding.

But i'm sure that if there would be a select statement to do this, it would be much faster than selecting 665 elements.

Thanks for any help on this.

hellomadhu
April 22nd, 2003, 01:32 AM
SELECT * FROM myTable where uniqueID=(select max(uniqueid) from mytable)

or

For SQL Server
------------------

SELECT Top 1 * FROM myTable

For Oracle
-------------
SELECT * FROM myTable ORDER BY uniqueID Limit 1

Avenger001
April 22nd, 2003, 12:24 PM
That was simple enough.
Worked great.

Thanks!!