My database contains a list of phone numbers which is of varchar type. Phone number may be in any of these formats
12323232323
1-232-323 2323
232-323-2323
2323232323
Instead of the –
symbol there may be (
)
,
.
or space
And if I search for 12323232323, 1-232-323 2323, 232-323-2323, or 2323232323 it should display all these results. I need to write a query for this.
I think it is not efficient to do this realtime, I propose two options.
clean the data, so there will be only one format.
add another column which contains the clean data, so when you search, you search for this column, when display you can display the various format data.
I agree with James, but if you really need to search the database as it is, perhaps MySQL's REPLACE operator will get you where you need to go. Something like
select * from mytable where replace(crazynumber,'-','')='23232323';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With