×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

need to write sql select last row of table

need to write sql select last row of table

need to write sql select last row of table

(OP)
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.

RE: need to write sql select last row of table

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:
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.mspx

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

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: need to write sql select last row of table

(OP)
thanks that helped.

RE: need to write sql select last row of table

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)

RE: need to write sql select last row of table

Is there an echo in here?

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

Steam Engine enthusiasts: www.essexsteam.co.uk

RE: need to write sql select last row of table

Right, is it one?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources