Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all rows where mycolumn is an integer value?

Tags:

sql

mysql

What would be a good way to select all the rows from a table where a column is an unsigned integer, for example here is some pseudo-sql

SELECT * FROM mytable WHERE mycolumn IS UNSIGNED INTEGER

So that strings 'abc' and numbers like '12.3' and '12.0' would not match, but integers like '123' would.

Where mycolumn is type text/varchar

like image 909
Timo Huovinen Avatar asked Dec 20 '22 22:12

Timo Huovinen


1 Answers

SELECT * FROM mytable WHERE mycolumn REGEXP '^[0-9]+$'

Shouldn't that be simple enough?

like image 94
Robin Castlin Avatar answered Mar 03 '23 20:03

Robin Castlin