How can I search for "1-800-flowers" by "1800flowers" in MySQL?
I have the data "1-800-flowers", but I want to find it by "1800flowers".
You're probably best off creating a second column that you fill with 1800flowers
(replacing all characters you want to ignore) and searching that. That way, you can make full use of indexing.
A quick way to convert all existing data would be
UPDATE table SET columnname_without_hyphens = REPLACE(columnname, "-", "");
If your problem is just ignoring hyphens, I may suggest using REPLACE
to eliminate them, like this:
SELECT ... WHERE REPLACE(column, '-', '') ...
Otherwise, if you're looking for strings that "sound alike", you may want to have a look at the SOUNDEX
function.
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