Detect if value is number in MySQL

Urbycoz picture Urbycoz · Feb 21, 2011 · Viewed 239.8k times · Source

Is there a way to detect if a value is a number in a MySQL query? Such as

SELECT * 
FROM myTable 
WHERE isANumber(col1) = true

Answer

Thiago Canto picture Thiago Canto · Dec 23, 2011

You can use Regular Expression too... it would be like:

SELECT * FROM myTable WHERE col1 REGEXP '^[0-9]+$';

Reference: http://dev.mysql.com/doc/refman/5.1/en/regexp.html