Updating Several Rows with MySQL
How can I update several rows in the same table in the one query? There are two columns and I'm using PHP 4.3.2 and MySQL 4.0.13.
How can I update several rows in the same table in the one query? There are two columns and I'm using PHP 4.3.2 and MySQL 4.0.13.
Mark Hensler posted this at 06:42 — 28th July 2003.
He has: 4,048 posts
Joined: Aug 2000
You can only update 2 or more records if you want the fields to be the same. (So you can't update one records with field_one=1 and record two with field_one=2)
Is this the case? If so, just edit the WHERE statement to include some identification for all desired records.
Mark Hensler
If there is no answer on Google, then there is no question.
nuk3 posted this at 08:16 — 28th July 2003.
They have: 238 posts
Joined: May 2002
Each field will have a different value. So what can I do?
Mark Hensler posted this at 18:56 — 28th July 2003.
He has: 4,048 posts
Joined: Aug 2000
If each record must have seperate values, then you'll have to run a seperate update query for each record. I've not found a way around that for MySQL 3.
MySQL 4, on the other hand, may have other options. I've heard of multi-table updates (similar to select queries with join statements), but I've not read much about them. I don't know if you could update multiple records within one table, but the capability may have been added as well.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.