Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

need to write sql select last row of table

Status
Not open for further replies.

ssala

Computer
Oct 20, 2005
2
0
0
US
i have a table contain 1000 of records. I need to display last row of the table.

please let me know how to do it in SQL. I tried all Select statement but could not get it. I can count total rows with Select Count(*) from Table; but how to get the last row.

 
Replies continue below

Recommended for you

What do you mean by 'last'? SQL does not define the order that data is stored in a table. If you have a Datestamp field, or a serial number field then you could use something like:
Select Top 1 myName, myID from myTable Order by myID DESC

See the TOP predicate in SQL books on line, downloaded from:


Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

Steam Engine enthusiasts:
 
Very simple (it depends what SQL engine are you using):

Firebird
select FIRST 1 from <your table> order by <field> DESC

Access
select TOP 1 from <your table> order by <field> DESC

If you are using else, search for something equivalent in it's sql language reference (for example Interbase has ROWS clause)
 
Status
Not open for further replies.
Back
Top