MySQL query to remove a value with only numbers in a column


For this, you can use REGEXP. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> ClientCode varchar(100)
   -> );
Query OK, 0 rows affected (0.56 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Chris902');
Query OK, 1 row affected (0.21 sec)

mysql> insert into DemoTable values('Robert_');
Query OK, 1 row affected (0.14 sec)

mysql> insert into DemoTable values('903');
Query OK, 1 row affected (0.15 sec)

mysql> insert into DemoTable values('123_David');
Query OK, 1 row affected (0.21 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------------+
| ClientCode |
+------------+
| Chris902   |
| Robert_    |
| 903        |
| 123_David  |
+------------+
4 rows in set (0.00 sec)

Following is the query to SQL like statement “%[^0-9]%” not working −

mysql> select *from DemoTable where ClientCode REGEXP '.*[^0-9].*';

This will produce the following output −

+------------+
| ClientCode |
+------------+
| Chris902   |
| Robert_    |
| 123_David  |
+------------+
3 rows in set (0.04 sec)
raja
Published on 11-Jul-2019 15:15:07
Advertisements