Solved

overwriting existing table value and auto increment value

Posted on 2007-11-24
2
465 Views
Last Modified: 2010-04-21
Hi,

 I have a very simple table in a mysql database, which has the following columns,

id, tag, and count

The id column value is set to auto increment when I add a new value for tag and count. Instead of creating a new value each time for the column 'tag', is it possible to overwrite an existing value with the same value and then simply increase the value of count by 1.

eg: id =1. tag=world. count=20. If I then added the value 'world' again to the table, I would want to overwrite the previous value of count, and increase it by one to '21' and so on. Therefore, we would end up with a new row of id=1. tag=world, count=21 and so on. I don't mind if the id is changed, as long as the unique value for the tag, ie: 'world', is not replicated in the table.

Any help appreciated.

Thanks!
0
Comment
Question by:nhay59
2 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20342769
To update the existing column you would do
UPDATE tablename SET `count`=`count`+1, tag ='value' WHERE id=value_for_id (i.e 1)

to insert new row you would do

INSERT INTO  tablename SET `count`=`count`+1, tag ='value'

0
 

Author Closing Comment

by:nhay59
ID: 31410768
Thanks for the solution. Spot on!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question