Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL return only the rows which are numeric [duplicate]

Possible Duplicate:
How do I check to see if a value is an integer in MySQL?

I have been been trying to select only the numeric rows from a field in mysql.

A sample of the data in the database would be:

'1234543' '12f4231' 'fdfrgr34' etc.

I want my select statement to only return the numeric rows.

So in this case the only row I would get back would be the '1234543' row.

Any help would be greatly appreciated.

Thanks, Stefan.

like image 876
StefanHanotin Avatar asked Jan 31 '26 22:01

StefanHanotin


2 Answers

Try this

SELECT * FROM table_name WHERE column_name REGEXP '^[0-9]+$';
like image 200
Chris Avatar answered Feb 02 '26 13:02

Chris


You could use a regex, for positive numbers:

SELECT * FROM my_table WHERE my_column REGEXP '^[[:digit:]]+$'

Some adjustments are needed if you want to allow leading/trailing whitespace though.

like image 33
nos Avatar answered Feb 02 '26 14:02

nos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!