Page 1 of 2
UPDATE, updating only a specific value
Posted: Fri Aug 06, 2004 9:44 pm
by thundza
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.
Posted: Fri Aug 06, 2004 9:46 pm
by Joe
You should either add an integer column with auto_increment attributes or their may be a possibilty of jumping to the appropiate row, not too sure how though!
Posted: Fri Aug 06, 2004 9:52 pm
by thundza
I'd like to be able to do it without an ID column if that is possible. Anybody else know how to?
Posted: Fri Aug 06, 2004 9:55 pm
by Joe
You may be able to use
FIRST with some kind of incrementation taking place, again not to sure!
Posted: Fri Aug 06, 2004 10:03 pm
by thundza
Hmmm... not sure about the FIRST command, but I'll search through the rest of the site and see if there is any way.
Posted: Fri Aug 06, 2004 10:04 pm
by Joe
I was not too sure there myself actually, hehe
Posted: Fri Aug 06, 2004 10:10 pm
by feyd
update requires some unique way of identifying the record you wish to update, or you will update many rows.. You may be able to use conditionals like IF, or the loop WHILE, however I think those are a little more remote..
Posted: Fri Aug 06, 2004 10:30 pm
by thundza
Are there any ways you can specify (x,y) coordinates, like (3, 11), or whatever the cell's coordinates may be?
Posted: Fri Aug 06, 2004 10:31 pm
by Joe
Not that I know of

Posted: Fri Aug 06, 2004 10:32 pm
by feyd
I don't believe so, at least not one exposed through php. Could you explain why you are set against using an id?
Posted: Fri Aug 06, 2004 10:41 pm
by thundza
I don't have access to create new columns, so an ID wouldn't work.
Posted: Fri Aug 06, 2004 10:44 pm
by Joe
If you have access to creating and executing querys why cant you just create a new table via php/mysql?.
Posted: Fri Aug 06, 2004 10:45 pm
by feyd
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...
Posted: Fri Aug 06, 2004 11:01 pm
by thundza
I'll look into stored procedures...
The table I wish to modify is more complex than the simple example I gave, but the same basic concept of multiple identical values.
A temporary table might be the answer, I just wish there was a faster way. Thanks for all your help everybody.
Posted: Sat Aug 07, 2004 4:38 am
by JAM
Ugly hack but:
Code: Select all
update tblname set COLUMNB = 'K' limit 3
update tblname set COLUMNB = 'Y' limit 2
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...