So I went to mysql docs to check out if they had info on what to do. I found this

“[0-9]*” matches any number of digits, and “.*” matches any number of anything.

So, I tried them both out & have no result that back back.

The query I used.

SELECT * FROM table WHERE name LIKE '[0-9]*'
&
SELECT * FROM table WHERE name LIKE '.*'

and nothing showed up.. I had two rows with digits in the names & nothing showed up. What am I doing wrong?

'%[0-9]*%'
'%.*%'

If you mean any number between 0-9

then use

BETWEEN

I tried

SELECT * FROM table WHERE name LIKE '%[0-9]*%'
SELECT * FROM table WHERE name LIKE '%.*%'

and I got nothing from either query.. When I know there is numeric database in the rows I have.

I tried

SELECT * FROM table WHERE name BETWEEN 0 AND 9

and got result with all rows, even rows containing string data..

Could you give me some example queries?

I solved this using RLIKE

SELECT * FROM `category` WHERE name RLIKE '^[0-9]'

Between 0 and 9 works when the field is integer datatype. Who or what has a name that is an integer between 0 and 9. So the whole query just does not make sense. And then you admit that you have strings as names, so the datatype is probably char or varchar.

I suggest you re-think what you are doing with the name field and its datatype. Also, what if someone had the name 11 - they would be excluded of course, as would john21...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.