Skip to main content

Posts

Showing posts from 2016

How to update multiple fields in an SQL update statement

Syntax: /* the correct way of putting multiple fields together, using comma */ UPDATE `stories` SET `content`='Once upon a time ...', `update_time`=now() WHERE id=1; Note: there is no 'and' between the fields you are trying to update. You should use comma between each pair of the fields you are trying to update. Otherwise, you will likely get an '0' as the result value in the 'content' field without getting any error message. If you do the following, you will likely get an '0' in the 'content' field, without any error message /* the wrong way of putting multiple fields together, using 'and' */ UPDATE `stories` SET `content`='My Story' and `update_time`=now() WHERE id=1; See also:  http://stackoverflow.com/a/7375371