I have a query I need to run on almost 2000 strings where it would be very helpful to be able to do a list like you can with the “IN” operator but using the LIKE comparison operation.
For example I want to check to see if pet_name is like any of these (but not exact): barfy, max, whiskers, champ, big-D, Big D, Sally
Using like it wouldn’t be case sensitive and it can also have an underscore instead of a dash. Or a space. It will be a huge pain in the ass to write a large series of OR operators. I am running this on MySQL 5.1.
In my particular case I am looking for file names where the differences are usually a dash or an underscore where the opposite would be.
You could do something like this –
It will give a non-zero value (>0) if there is a pet_name we are looking for.
But I’d suggest you to create a table
petnamesand use SOUNDS LIKE function to compare names, in this case ‘bigD’ will be equal to ‘big-D’, e.g.:Example: