Update MySQL column based on email address?


Let us first create a table −

mysql> create table DemoTable
   -> (
   -> EmailAddress varchar(20),
   -> Score int
   -> );
Query OK, 0 rows affected (1.05 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Chris@gmail.com',67);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable values('Robert@gmail.com',57);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('David@gmail.com',98);
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------------------+-------+
| EmailAddress     | Score |
+------------------+-------+
| Chris@gmail.com  |    67 |
| Robert@gmail.com |    57 |
| David@gmail.com  |    98 |
+------------------+-------+
3 rows in set (0.00 sec)

Here is the query to update MySQL column based on email address −

mysql> update DemoTable
   -> set Score=89
   -> where EmailAddress='Robert@gmail.com';
Query OK, 1 row affected (0.25 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Let us check the table records once again −

mysql> select *from DemoTable;

This will produce the following output −

+------------------+-------+
| EmailAddress     | Score |
+------------------+-------+
| Chris@gmail.com  |    67 |
| Robert@gmail.com |    89 |
| David@gmail.com  |    98 |
+------------------+-------+
3 rows in set (0.00 sec)

Updated on: 18-Dec-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements