By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

URGENT(HOW TO LOCATE LAST RECORD IN DATABASE)

P: n/a

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!
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <da***********@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...

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!

Jul 19 '05 #2

P: n/a
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"
Jul 19 '05 #3

P: n/a
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" <da***********@hotmail.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...

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!

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.