Skip to content
Advertisement

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

Advertisement

Answer

SELECT * 
FROM mixedvalues 
WHERE value REGEXP '^[0-9]+$';
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement