URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)

Discussion in 'ASP General' started by Daniel Ng, Oct 1, 2004.

  1. Daniel Ng

    Daniel Ng Guest

    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.


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Daniel Ng, Oct 1, 2004
    #1
    1. Advertising

  2. What makes "record 3" the "last record"?

    You realize that a table is an unordered set of rows, right? In order to
    have a *consistent* result for the "last" row you need to tell the database
    how to determine last (e.g. using an ORDER BY or MAX/MIN aggregate).

    --
    http://www.aspfaq.com/
    (Reverse address to reply.)




    "Daniel Ng" <> wrote in message
    news:...
    >
    > 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.
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Aaron [SQL Server MVP], Oct 1, 2004
    #2
    1. Advertising

  3. 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"
    Bob Barrows [MVP], Oct 1, 2004
    #3
  4. Your posts are no more urgent than anyone else's. Please stop SHOUTING in
    your subject lines and trying to be more important than everyone else. Your
    question will not get answered any sooner by doing this. If anything, it
    will have the opposite effect.

    Ray at work

    "Daniel Ng" <> wrote in message
    news:...
    >
    > 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.
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Ray Costanzo [MVP], Oct 1, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sangram
    Replies:
    16
    Views:
    1,959
  2. Johny
    Replies:
    8
    Views:
    380
  3. Matt
    Replies:
    1
    Views:
    157
    Aaron Bertrand [MVP]
    Jan 10, 2004
  4. Atul Dongargaonkar
    Replies:
    2
    Views:
    94
    Martin DeMello
    Oct 6, 2010
  5. mrichardson
    Replies:
    1
    Views:
    250
    Brian Helterline
    Sep 16, 2004
Loading...

Share This Page