Posted by: james | October 7, 2009

How to Increment Field in MySQL which is not auto increment.

for ex. if we have table, whose name is test. and it has two fields frist and second.
and if you want to increment the first field though its not auto increment field or not primary key.
then how can do this??

so for that you have to make any field as unique key, means first of all make unique key any field of that table and then run this query, so you will get expected output.. (I hope so..)

insert into test (frist,second) values(1,2) on duplicate key update frist=frist+1;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: