Searching a Phone Number in a MySQL Database Table with two or more phone field columns having phone number in different formats
I have a database table with 2 columns - phone and mobile.
Both columns have phone numbers in different formats like:
+(91) 950-232-9020
+91 950-232-9020
+91 9502329020
09502329020
From my PHP scriptm if I want to search phone number '9502329020',
I want it to return 4 rows.
So far I have found 1 solution using %
after every digit as:
Select * from table
where phone like '%9%5%0%2%3%2%9%0%2%0' or
mobile like '%9%5%0%2%3%2%9%0%2%0';
But if I have to search millions of rows, I would need an optimized solution.
Can anyone help me out with an optimized solution, somewhat like using regex in a MYSQL query.
Note: While saving in the database, phone numbers are saved in user friendly formats.