05 July 2011

When you update a mysql table you should use coma between the fields not "and"

Well i learned this the hard way... i was debugging an sql update for couple of minutes and it seems that the only error that i had was the coma between the fields. For example:

sql> update table_name set field1="value1" and field2="value2" where cond1="val1";

is wrong. Also, in some cases (randomly for me) it was resetting the existing value of "field1". The correct version should be with coma "," instead of "and", like this:

sql> update table_name set field1="value1", field2="value2" where cond1="val1";

I found my mistake using phpMyAdmin.

No comments:

Post a Comment