Question

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

Was it helpful?

Solution

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

OTHER TIPS

SELECT * 
FROM mixedvalues 
WHERE concat('',value * 1) = value;

Reference: Detect if value is number in MySQL

You were close :

SELECT * 
FROM mixedvalues 
WHERE value > 0;

SQLFiddle

SELECT * FROM mixedvalues 
WHERE value > 0 
ORDER BY CAST(value as SIGNED INTEGER) ASC

List item has string continue with numbers

$string = "Test";

select * from table where columnname REGEXP "$string-*[0-9]+"; 

You can filter your result set using the ISNUMERIC function:

SELECT value
FROM #mixedvalues 
where ISNUMERIC(value)=1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top