MySQL Query to Remove First Digit



For this, use SUBSTR(). Following is the syntax −

update yourTableName set yourColumnName=substr(yourColumnName,2);

Let us first create a table −

mysql> create table DemoTable607 (Value varchar(100));
Query OK, 0 rows affected (0.69 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable607 values('83967364');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable607 values('10939432');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable607 values('932111');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable607;

This will produce the following output −

+----------+
| Value    |
+----------+
| 83967364 |
| 10939432 |
| 932111   |
+----------+
3 rows in set (0.00 sec)

Here is the MySQL query to remove first digit −

mysql> update DemoTable607 set Value=substr(Value,2);
Query OK, 3 rows affected (0.14 sec)
Rows matched: 3 Changed: 3 Warnings: 0

Let us check the table once again −

mysql> select *from DemoTable607;

This will produce the following output −

+---------+
| Value   |
+---------+
| 3967364 |
| 0939432 |
| 32111   |
+---------+
3 rows in set (0.00 sec)
Updated on: 2019-08-22T13:05:05+05:30

731 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements