Search code examples
mysqlsqlnumericvarchar

MySQL - Select only numeric values from varchar column


Consider the following table :

create table mixedvalues (value varchar(50));

insert into mixedvalues values 
('100'),
('ABC100'),
('200'),
('ABC200'),
('300'),
('ABC300'),
('400'),
('ABC400'),
('500'),
('ABC500');

How can I write a select statement that would only return the numeric values like

100
200
300
400
500

SQLFiddle


Solution

  • SELECT * 
    FROM mixedvalues 
    WHERE value REGEXP '^[0-9]+$';