Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select values that begin with a number

I have a table with a column containing data that begin with numbers too, on MySQL

How can I select the rows that begin only with a number?

like image 360
Omega Avatar asked Sep 06 '25 15:09

Omega


2 Answers

SELECT * FROM YourTable WHERE YourColumn regexp '^[0-9]+'
like image 167
Sarfraz Avatar answered Sep 09 '25 04:09

Sarfraz


Yet another way:

WHERE LEFT(columnName,1) IN ('0','1','2','3','4','5','6','7','8','9')

and with common charsets and collations, this would work and use an index on the column:

WHERE columnName >= '0' AND columnName < ':'
like image 39
ypercubeᵀᴹ Avatar answered Sep 09 '25 06:09

ypercubeᵀᴹ