How to update data in a database table using phpMyAdmin?

Asked 3 years ago 146 views 1 answer Modified 1 days ago
8

I have a table named my_tbl in phpMyAdmin, and I want to update all values in a column named my_col at once.

My current SQL query is:

UPDATE `my_tbl` SET `my_col` = 'B' WHERE `my_tbl`.`id` = *;

The column my_col currently has the value 'A', and I want to replace all these values with 'B'. How can I accomplish this?

Imran Nadwi
50 reputation

1 Answer

15

There are several ways to update data in a database table using phpMyAdmin. Here are the most common approaches:

Method 1: Update all rows in a column

If you want to update ALL values in the my_col column from 'A' to 'B', use:

UPDATE `my_tbl` SET `my_col` = 'B' WHERE `my_col` = 'A'

Method 2: Update all rows regardless of current value

If you want to set ALL rows in the column to 'B' regardless of their current value:

UPDATE `my_tbl` SET `my_col` = 'B'

Method 3: Update specific rows by ID

If you want to update only specific rows by their ID:

UPDATE `my_tbl` SET `my_col` = 'B' WHERE `id` = 3

Important: Always backup your data before running UPDATE queries, especially when updating multiple rows. You can also use the LIMIT clause to restrict the number of affected rows for safety.

CodingerWeb
answered 3 years ago
You can use Markdown to format your answer.
Last edited: 3 years ago
Preview: