MySQL Update

MySQL Update

MySQL update syntax and examples.

MySQL Update syntax

UPDATE table_name SET col1=val1;
UPDATE table_name SET col1=val1, col2=val2, col3=val3, … WHERE condition;

Table test

IDNAME
1abc
2def
3ghi
4jkl

Update example

UPDATE test SET name = 'aaa';

UPDATE test SET id=22, name='bbb' WHERE id=2;

UPDATE test SET name='ddd' WHERE id=4;

SELECT * FROM test;

Query Result

IDNAME
1aaa
22bbb
3aaa
4ddd