Basic Update query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys

I'm pretty new to mysql and was just wondering if you can update multiple
fields at the same time i.e:
UPDATE tablename SET field1 = value1 AND field2 = value 2 etc... WHERE
field0 = value;


Re: Basic Update query

Tony Wainwright wrote:
Quoted text here. Click to load it

Yes, you this is possible... but you can also use the following syntax:

UPDATE tablename (field1, field2, ..., fieldn) SET VALUES (value1,
value2, ..., valuen) WHERE field0  = value;


Re: Basic Update query

Quoted text here. Click to load it

Yes, but you don't use AND, you use a comma to separate different
field assignments.

I think the statement as you gave it would work, but it would only
set field1, and it would do some funky boolean calculations for
its value:

UPDATE tablename SET field1 = ((value1) AND (field2 = value2)) WHERE
                            ^ assignment            ^comparison
field0 = value;

Instead use:

UPDATE tablename SET field1 = value1, field2 = value2, ... WHERE
field0 = value.

                        Gordon L. Burditt

Site Timeline