
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to select only non - numeric values from varchar column in MySQL?
You need to use REGEXP for this. The syntax is as follows
SELECT *FROM yourTableName WHERE yourColumnName REGEXP '[a-zA-Z]';
To understand the concept, let us create a table. The query to create a table is as follows
mysql> create table SelectNonNumericValue -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserId varchar(100) -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command. The query is as follows
mysql> insert into SelectNonNumericValue(UserId) values('123John'); Query OK, 1 row affected (0.12 sec) mysql> insert into SelectNonNumericValue(UserId) values('58475Carol98457Taylor24'); Query OK, 1 row affected (0.52 sec) mysql> insert into SelectNonNumericValue(UserId) values('199575Sam124'); Query OK, 1 row affected (0.14 sec) mysql> insert into SelectNonNumericValue(UserId) values('Mike2456'); Query OK, 1 row affected (0.14 sec) mysql> insert into SelectNonNumericValue(UserId) values('1000'); Query OK, 1 row affected (0.12 sec) mysql> insert into SelectNonNumericValue(UserId) values('1001'); Query OK, 1 row affected (0.21 sec) mysql> insert into SelectNonNumericValue(UserId) values('10293Bob'); Query OK, 1 row affected (0.13 sec) mysql> insert into SelectNonNumericValue(UserId) values('David'); Query OK, 1 row affected (0.30 sec) mysql> insert into SelectNonNumericValue(UserId) values('2456'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using a select statement. The query is as follows
mysql> select *from SelectNonNumericValue;
The following is the output
+----+-------------------------+ | Id | UserId | +----+-------------------------+ | 1 | 123John | | 2 | 58475Carol98457Taylor24 | | 3 | 199575Sam124 | | 4 | Mike2456 | | 5 | 1000 | | 6 | 1001 | | 7 | 10293Bob | | 8 | David | | 9 | 2456 | +----+-------------------------+ 9 rows in set (0.00 sec)
Here is the query to select non-numeric values
mysql> select *from SelectNonNumericValue WHERE UserId REGEXP '[a-zA-Z]';
The following is the output that ignores the numeric values
+----+-------------------------+ | Id | UserId | +----+-------------------------+ | 1 | 123John | | 2 | 58475Carol98457Taylor24 | | 3 | 199575Sam124 | | 4 | Mike2456 | | 7 | 10293Bob | | 8 | David | +----+-------------------------+ 6 rows in set (0.00 sec)
- Related Articles
- How to select only MySQL date from datetime column?
- Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
- How to select distinct value from one MySQL column only?
- MySQL query to get max id from varchar type and the values in numeric?
- MySQL randomly select 2 values from column values?
- How to alter a MySQL Column from varchar(30) to varchar(100)?
- How to select only numeric strings in MongoDB?
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- How to select only numeric columns from an R data frame?
- GROUP BY and display only non-empty column values in MySQL
- MySQL query to get the max value with numeric values in varchar field?
- How to cast and update a numeric value from string column only where applicable in MySQL?
- Need help selecting non-empty column values from MySQL?
- MySQL query to replace backslash from a varchar column with preceding backslash string values
- MySQL select only a single value from 5 similar values?

Advertisements