For this, use CASE statement with UPDATE command. Let us first create a table −
mysql> create table DemoTable1874 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Amount varchar(100) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1874(Amount) values('3450'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('190'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('7600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('4500'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1874;
This will produce the following output −
+----+--------+ | Id | Amount | +----+--------+ | 1 | 3450 | | 2 | 190 | | 3 | 7600 | | 4 | 4500 | +----+--------+ 4 rows in set (0.00 sec)
Here is the query to insert Euro and Dollar symbol to a column in MySQL −
mysql> UPDATE DemoTable1874 SET Amount= CASE WHEN Id = 1 THEN Concat('$','',Amount) WHEN Id = 3 THEN Concat('€','',Amount) else Amount END ; Query OK, 2 rows affected (0.00 sec) Rows matched: 4 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1874;
This will produce the following output −
+----+---------+ | Id | Amount | +----+---------+ | 1 | $3450 | | 2 | 190 | | 3 | €7600 | | 4 | 4500 | +----+---------+ 4 rows in set (0.00 sec)