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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivalent of (Last) Function

Status
Not open for further replies.

ind

Programmer
Mar 9, 2000
121
US
I am developing a database in an access project (.adp) and I need to use the (Last) function. What is the equivalent that will work with SQL Server??????????


Thanks for the help
 
select top(10) t.* from (select * from table order by onecolumn desc) t John Fill
 
Need help

I have to create a module which allow the user to input record into the table. How do I show him the last 5 records he's recently input

Thanks in advance
 

There is no equivalent for LAST in SQL Server. Table order implied by LAST (and FIRST) is not a relational concept. SQL Server is more compliant to the relational model than Access in this regard.

If the table in question has an identity column, datetime column, or other incrementing column then the MAX function can be used in place of LAST. You can also use the TOP predicate to select the Last n (or First n) rows from a table.

Examples:

/* Find first value */
Select min(colA) From table
Select Top 1 colA From table order by colA

/* Find last value */
Select max(colA) From table
Select Top 1 colA From table order by colA desc Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time.
NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top