Forum Moderators: coopster

Message Too Old, No Replies

Bulk MySQL Edit

         

inveni0

7:40 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



What would be the best way to bulk edit a MySQL table?

For instance, let's say I have rows set up as:

Key Value
1 blue
2 red
3 red
4 blue
5 red

Now, my goal is to change Keys 2, 3 and 5 to a blue value. Is there a way to mass edit these? For instance to tell my database to edit 2-5 and change all to blue?

dmorison

7:44 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two options here. If the rows that you wish to edit are always going to be sequential, then you can do this:

UPDATE table SET value='blue' WHERE key >= 3 AND key <= 5

Alternatively, you can use the IN clause:

UPDATE table SET value='blue' WHERE key IN (2,3,5)

jatar_k

7:49 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



or

update mytable set value='blue' where id BETWEEN 2 and 5;

[dev.mysql.com...]