Re: URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 10/01/04


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" 


Relevant Pages

  • Re: Polymorphism sucks [Was: Paradigms which way to go?]
    ... >>>single table, is a relational database. ... > by their Heading, which must of course now be unique. ... > So the difference, in Codd's paper, is that a Relation is an unordered Set ... I do however have Chris Dates "Introduction to Database ...
    (comp.object)
  • Re: Polymorphism sucks [Was: Paradigms which way to go?]
    ... >> single table, is a relational database. ... Relation, have multiple Attributes with the same Heading, as each ... So the difference, in Codd's paper, is that a Relation is an unordered Set ... 'Entity-Relationship modeling', ...
    (comp.object)
  • Re: Get last record of recordset that holds data
    ... of an ADO recordset that holds a field that is not NULL? ... return records in historical order, later maintaince, indexing, ... What you say is true with a relational database. ... This email account is my spam trap so I ...
    (microsoft.public.data.ado)