PDA

View Full Version : Update multiple rows?


NeoMoon
11-28-2008, 10:28 PM
How would I go about updating multiple rows?

Like "UPDATE `table` SET `this` = 'that' WHERE `this` = 'that', `this` = 'otherthat'"?

Thanks in advance,
NeoMoon

iainmackay85
11-28-2008, 11:58 PM
How would I go about updating multiple rows?

Like "UPDATE `table` SET `this` = 'that' WHERE `this` = 'that', `this` = 'otherthat'"?

Thanks in advance,
NeoMoon

your right!

UPDATE `table` SET `this` = 'that' WHERE `this` = 'that' OR `this` = 'otherthat';

alternatively:
UPDATE `table` SET `this` = 'that' WHERE `this` LIKE '%hat';

or:
UPDATE `table` SET `this` = 'that' WHERE `this` > '100' AND `this` < '200';

depends on your data

regards,

NeoMoon
11-29-2008, 06:48 AM
your right!

UPDATE `table` SET `this` = 'that' WHERE `this` = 'that' OR `this` = 'otherthat';

alternatively:
UPDATE `table` SET `this` = 'that' WHERE `this` LIKE '%hat';

or:
UPDATE `table` SET `this` = 'that' WHERE `this` > '100' AND `this` < '200';

depends on your data

regards,Thanks. :)

iainmackay85
11-29-2008, 05:58 PM
No problem, have fun!

for future reference w3schools.com (http://www.w3schools.com/sql/default.asp)

brazenskies
11-30-2008, 12:36 PM
also if you're updating on a buch of IDs it's simple to use IN...


UPDATE `table` SET `this` = 'that' WHERE id IN (1,2,45,654,7778,98)


That will update all rows with IDs in that array. Alternatively you can also do it with text names, but better to stock to primary key

guelphdad
11-30-2008, 03:27 PM
brazenskies, a primary key doesn't have to be numeric in nature, you are probably thinking of using an auto incrment column as a primary key as many people use that option but it isn't necessary. a primary key is a column or set of columns in the row that identify the data as unique.

brazenskies
11-30-2008, 03:57 PM
I was really just using ID as an example. I was more suggesting that you would update the colums on whatever primary key you had set, ID being the example in this instance.