Consider a table category in a database, with column typeis. The datatype is varchar with values
typeis
------
2.5.1
12
1.1.1
11
letters12
.........
I want to write a query that only returns records with “.” and numbers from 0-9
For example
2.5.1
1.1.1
So far, I have
select typeis from category where typeis
not in
(select typeis from category where typeis REGEXP '[^0-9 \.]+')
and typeis in
(select typeis from category where typeis REGEXP '^[0-9]+[\.]')
which seems to work. The problem is that it takes over 3secs for just 1500 records. I would like to make it simpler and faster with just one REGEXP, instead of having nested select
Try:
^[0-9]+\.[0-9]+(\.[0-9]+)*This should match things starting with a number(s) including a dot somewhere in the middle, and ending with numbers, and as many of these patterns as it would like.