Solved

overwriting existing table value and auto increment value

Posted on 2007-11-24
2
463 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
Comment Utility
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
Comment Utility
Thanks for the solution. Spot on!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Creating and Managing Databases with phpMyAdmin in cPanel.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now