Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to write sql select last row of table

Status
Not open for further replies.

ssala

Computer
Joined
Oct 20, 2005
Messages
2
Location
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.

 
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:
 
thanks that helped.
 
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)
 
Is there an echo in here?

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

Steam Engine enthusiasts:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top