Re: URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)
From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 10/01/04
- Next message: Steven Burn: "ATTN: Daniel Ng"
- Previous message: Aaron [SQL Server MVP]: "Re: URGENT(COUNTING OF RECORD IN DATAABSE USING ASP)"
- In reply to: Daniel Ng: "URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)"
- Next in thread: Ray Costanzo [MVP]: "Re: URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 1 Oct 2004 10:32:21 -0400
Daniel Ng wrote:
> Thanks for the 2 guys how hep to to solve to count the number of
> recount in forum. I'm done wif that. Got 1 more question..
>
> Example
> Record 1: ID 2 VALUE 2
> Record 2: ID 3 VALUE 3
> Record 3: ID 2 VALUE 1
>
> How can i retrieve the VALUE of the last record of ID 2 using ASP?? In
> this case, the asnwer given to me should be Record 3.
>
You need to rid yourself of the idea that there is such a thing as a "last"
record in a table. A table in a relational database is defined as an
unordered set of rows and columns. The only way to impose a reliable and
consistent order on a set of rows is to use an ORDER BY clause in a sql
statement. Having said that, I assume that you are defining the "last"
record in your table as the record containing hte highest ID value. There
are a couple ways to return this record, which may or may not work depending
on the type and version of database you are using (please, always tell us
this information):
SELECT Top 1 <column_list>
FROM <table_name>
ORDER BY ID DESC
SELECT <column_list>
FROM <table_name>
WHERE ID =
(SELECT Max(ID) FROM <table_name>)
There are other techniques, but this should get you going.
Bob Barrows
-- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
- Next message: Steven Burn: "ATTN: Daniel Ng"
- Previous message: Aaron [SQL Server MVP]: "Re: URGENT(COUNTING OF RECORD IN DATAABSE USING ASP)"
- In reply to: Daniel Ng: "URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)"
- Next in thread: Ray Costanzo [MVP]: "Re: URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|