0

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?

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by drjohn
0
'%[0-9]*%'
'%.*%'

If you mean any number between 0-9

then use

BETWEEN

Edited by finito: n/a

0

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?

0

I solved this using RLIKE

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

0

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...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.