Don't do that !!! You will eventually get the wrong row when someone else inserts after you. Use last_insert_id().
MySQL List wrote:
Nevermind I got it....
$next_number = $dbh->selectrow_array(qq{ SELECT MAX(id) FROM whatever_table });
Richard.
----- Original Message ----- From: "MySQL List" <[EMAIL PROTECTED]> To: "Bhavin Vyas" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, March 30, 2003 9:44 PM Subject: Re: Help With Default Value
Ok, how do I get the MAX(id)?this:
Thanks, Richard
----- Original Message ----- From: "Bhavin Vyas" <[EMAIL PROTECTED]> To: "MySQL List" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, March 30, 2003 7:59 PM Subject: Re: Help With Default Value
First option, I don't think, is possible. Reg. 2, You can get MAX(Id) before inserting, increment it by 1 in your script and then Insert 'gc<Id>' as the invoice_id value.
Bhavin. ----- Original Message ----- From: "MySQL List" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, March 30, 2003 7:23 PM Subject: Help With Default Value
I am trying to do one of two things.
First I'd rather do this, but if not possible, then the other way that I'll describe will suffice.
1) I need to have a default value of a column named "invoice_id" be
correctColumn names of importance: id invoice_id
id is auto_increment and BIGINT unsigned. invoice_id needs to be "gc"+ id
How can I have invoice_id have that as default? in other words if it's inserting data into that table, and it's the first record, then id would = 1. So I need invoice_id to be gc1
Is that possible?
2) If 1 is not possible, then how can I get the value of id of the one I
just inserted? Is it possible to get that at the same
time as I insert it, so I can then UPDATE that invoice_id with the
data?
If I need to clarify this, please by all means do let me know.
Thank you, kindly, Richard
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]