How can you make modifications to the data retrieved with MySQL?

To make changes to the data retrieved, you can use an UPDATE statement, which is used to modify the data in a table.

Here is the grammar.

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Suppose there is a table named students, with fields id, name, and age. Now, if we want to change the name of the student with id 1 to “Alice” and update their age to 20, we can execute the following UPDATE statement:

UPDATE students
SET name = 'Alice', age = 20
WHERE id = 1;

Please note:

  1. Exercise caution when using the UPDATE statement, as it directly impacts the data in the table.
  2. When executing an UPDATE statement, be sure to use a WHERE clause to specify the rows to be updated, otherwise all rows in the table will be updated.
bannerAds