Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HoW to select the last row of a table ?

Posted on 1998-09-15
8
Medium Priority
?
232 Views
Last Modified: 2010-03-19
HoW to select the last row of a table in SQl Base 7?
What's the syntax?
0
Comment
Question by:nk51
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1090043
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.
0
 
LVL 2

Expert Comment

by:odessa
ID: 1090044
What do you mean last, last in witch order, by WHAT?
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1090045
p.s. autonumber columns are also a good method to select last one created.
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:nk51
ID: 1090046
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
???
0
 
LVL 4

Expert Comment

by:mitek
ID: 1090047
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


0
 

Author Comment

by:nk51
ID: 1090048
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.
0
 

Accepted Solution

by:
JCreson earned 30 total points
ID: 1090049
You can use the MAX(Key_Field_Name) aggregate function to get you to the right row, if your Key_field is numeric or a date.  However, if your key is text you will have to sort first.

Try SELECT * From Table 1 WHERE Key_Field_Name
                 = (SELECT MAX(<Key_Field_Name>) from Table1)

Good luck
0
 

Author Comment

by:nk51
ID: 1090050
Max is a good solution.
Thanks.

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question