UPDATE, updating only a specific value
Moderator: General Moderators
UPDATE, updating only a specific value
Hey, I am somewhat new to MySQL, but I understand (I think) the UPDATE Syntax... UPDATE tblname SET columnname = somevalue WHERE somecondition. But, lets say i have a database like this:
COLUMNA COLUMNB
X......................Y
X......................Y
X......................Y
X......................Y
... and it continues on like this, where every value in COLUMNA is the same, and every value in COLUMNB is the same... but, I want to UPDATE the database so it is like this.
COLUMNA COLUMNB
X......................Y
X......................K <----I only want to change this value to K
X......................Y
X......................Y
... but with my knowledge, i'm not sure how to update a specific value like that where conditional statements won't help. I'm sure it's possible though, and would appreciate any help.
COLUMNA COLUMNB
X......................Y
X......................Y
X......................Y
X......................Y
... and it continues on like this, where every value in COLUMNA is the same, and every value in COLUMNB is the same... but, I want to UPDATE the database so it is like this.
COLUMNA COLUMNB
X......................Y
X......................K <----I only want to change this value to K
X......................Y
X......................Y
... but with my knowledge, i'm not sure how to update a specific value like that where conditional statements won't help. I'm sure it's possible though, and would appreciate any help.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
hmmm, then you may be able to create a stored procedure to alter it.. http://dev.mysql.com/doc/mysql/en/Store ... dures.html
In the example you gave, all the records were the same, is this true of the table you wish to modify?
Additionally, there is a potential to create a temporary table with consequtive numbers stored in it so you may "count" up to the row you need to alter...
In the example you gave, all the records were the same, is this true of the table you wish to modify?
Additionally, there is a potential to create a temporary table with consequtive numbers stored in it so you may "count" up to the row you need to alter...
Ugly hack but:
If running these two directly after each other the result would be as expected according to the data provided in the original post. If this approach would work is depending on how the actual table youre about to use looks like...
Code: Select all
update tblname set COLUMNB = 'K' limit 3
update tblname set COLUMNB = 'Y' limit 2