update multiple fields

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

update multiple fields

Post by ziggy1621 »

here is an easy one.. I'm just having a brain fart...

I want to update multiple fields chronologically by the "id" field.

Something like this in theory (but my syntax is off)

Code: Select all

UPDATE `table` SET `field` = 'blah' WHERE `id` = '1-7';"
thanks in advance
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

UPDATE `table` SET `field1` = 'blah', `field2` = 'blah', `field3` = 'blah' WHERE `id` = '1-7'
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

Pimptastic wrote:

Code: Select all

UPDATE `table` SET `field1` = 'blah', `field2` = 'blah', `field3` = 'blah' WHERE `id` = '1-7'
thanks for the response. sorry, let me better clarify... I want to update field 'category1' to equal '2a' for id '1-7'. this is what i have, but only alters where id=1

Code: Select all

UPDATE `listings` SET `category1` = '2a' WHERE `id` = '32-51';
thanks
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

off the top of my head

Code: Select all

UPDATE `listings` SET `category1` = '2a' WHERE `id` => 1 AND `id` <= 7
or

Code: Select all

UPDATE `listings` SET `category1` = '2a' WHERE `id` BETWEEN 1 AND 7
or

Code: Select all

UPDATE `listings` SET `category1` = '2a' WHERE `id` IN(1, 2 ,3, 4, 5, 6, 7)
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

the second works beautifully... thanks
Post Reply