Link to home
Start Free TrialLog in
Avatar of nk51
nk51

asked on

HoW to select the last row of a table ?

HoW to select the last row of a table in SQl Base 7?
What's the syntax?
Avatar of cymbolic
cymbolic

What is the last row of a table?  Is it the last one written, or is it the last one physically placed on the last allocated page?  I am not being rhetorical.  In this environment, "Last" row does not have a precise meaning.  If you mean the last one created, or last one updated, then you can use a timestamp column and select the row with the max() value on that column, otherwise you need to figure out how to mark and retrieve the last row in your own terms.
What do you mean last, last in witch order, by WHAT?
p.s. autonumber columns are also a good method to select last one created.
Avatar of nk51

ASKER

Sorry, I'm french so my english is bad.
I'm searching how to select the last created row of a table.
This table is sorted by increase order on a primary key (column_name).
I only wanted to know if a  similar syntax as this ACCESS requete exist in SQLBAse7 :
select last(column_name) from table_name
???
Here is an answer.
One way in SQL Server is:

DECLARE @last_key varchar(255) -- or int, or whatever

-- this will select the last primary key to a variable
SELECT @last_key = column_name
  FROM tab ORDER BY column_name

-- this will select the last row by that key
SELECT * FROM tab WHERE column_name = @last_key


Avatar of nk51

ASKER

To cymbolic :
I work an a table on which I can't add a column.
My first question was wrong writed.
I use Delphi 3.0 to ask a SQLbase 7 Database.
And I only want to know if it exist a direct SQL expression to select the last one created.

To mitek :
I can't use a variable because I'm using Delphi 3 to ask a SQLbase 7 database.
ASKER CERTIFIED SOLUTION
Avatar of JCreson
JCreson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nk51

ASKER

Max is a good solution.
Thanks.