Aruns
Aruns

Reputation: 49

Search inside columns which has space and multiple combination of phone numbers

I've a table which contains customer phone numbers, this numbers are filled with different formats, for eg some times, +91 803 22 22 22 and some time +91802323232 and sometime 803242525. The question is when I do a search using mysql for eg select * from customer where phone LIKE %803222222% this is not showing any result, because the value stored inside the field has whitespace.

What will be the possible solution for this ?

Regards,

Upvotes: 0

Views: 26

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521279

Remove spaces from the phone field before doing the LIKE check:

SELECT *
FROM customer
WHERE REPLACE(phone, ' ', '') LIKE '%803222222%'; -- matches +91 803 22 22 22

Upvotes: 2

Related Questions