0

I have a data which contain string output. I want to select the data with only numeric and its length between 10 or 11. How to achieve that in MYSQL?

My Data :

0123458921
12344asd12341
012-38jh213a
12398798797

Expected Output :

0123458921
12398798797
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Amirul Fahmi
  • 299
  • 2
  • 3
  • 10

2 Answers2

2

We can combine both where clause to one to improve performance

SELECT * 
FROM your_table
WHERE column_name REGEXP '^[0-9]{10,11}$' 

http://sqlfiddle.com/#!9/cc044e/2

Naruto
  • 4,221
  • 1
  • 21
  • 32
0

You can use the below query.

SELECT * 
FROM your_table
WHERE column_name REGEXP '^[0-9]+$' and length(column_name) in (10,11)

Check Demo Here

Arun Palanisamy
  • 5,281
  • 6
  • 28
  • 53