Home >Database >Mysql Tutorial >How to Update a Specific Column in MySQL Without Affecting Other Columns?
Updating a Column in MySQL
The goal is to update the values in a specific column ("col_a") of a table ("table1") while leaving other columns ("col_b") untouched. Attempting to use the INSERT statement to achieve this won't work.
Solution:
To update a selected column, you must utilize the UPDATE statement. The syntax is as follows:
UPDATE table_name SET column_name = new_value WHERE condition;
Example:
To set the values of "col_a" for rows with specific "key_col" values, use the following query:
UPDATE table1 SET col_a = 'foo' WHERE key_col = 'k1'; UPDATE table1 SET col_a = 'bar' WHERE key_col = 'k2';
The above is the detailed content of How to Update a Specific Column in MySQL Without Affecting Other Columns?. For more information, please follow other related articles on the PHP Chinese website!