visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: problem in max select max(Company_ID)


By: preeth U.S.A.  Date: 22/09/2004 00:00:00  English  Points: 125 Status: Answered
Quality : Excellent
Hi to all EEE

I have a table with an auto_increment field.

Is there a quick way to find out what the value of the auto_increment field of the last row in the table is?
---

I have tried this

strsql = "select max(Company_ID) from company"
rs1.open strsql,con

its giving error as..

ADODB.Fields error '800a0cc1'

ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.

/kingfisher/addcompany2.asp, line 28

the line 28 is

<%=rs1("Company_ID")%>

Thx in advance
Preet
By: VGR Date: 22/09/2004 18:28:00 English  Type : Answer
of course, because the returned column is named "max(Company_ID)", not "Company_ID" :D :D :D

use this technique :

strsql = "select max(Company_ID) as a from company"

and in the line 28

<%=rs1("a")%>


you've also other techniques, but that one will do the job.


By: preeth Date: 22/09/2004 18:42:00 English  Type : Comment
Thx VGR, full points
By: preeth Date: 22/09/2004 18:44:00 English  Type : Comment
Can u pls tell me the other Tech, along difference between this two

By: VGR Date: 22/09/2004 18:53:00 English  Type : Comment
the other one is related to the situation in which you usually NEED the value of the last auto_incremented ID.

this situation is when you just uinserted a new line :D

Thus the other technique involves trusting those :
either query MySql the usual way :
mysql> SELECT LAST_INSERT_ID();
<A HREF="http://www.mysql.com/doc/en/Miscellaneous_functions.html">http://www.mysql.com/doc/en/Miscellaneous_functions.html</A>

or query fromPHP via this wrapper :
mysql_insert_id -- Get the ID generated from the previous INSERT operation
<A HREF="http://www.php.net/manual/en/function.mysql-insert-id.php">http://www.php.net/manual/en/function.mysql-insert-id.php</A>

regards

Do register to be able to answer

EContact
browser fav
page generated in 1196.667910 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page