Solved

overwriting existing table value and auto increment value

Posted on 2007-11-24
2
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update joined tables 2 62
java mysql insert application 14 44
MySQL stored procedure returning null values 4 22
Not listening to where 1 18
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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