Skip to content
Advertisement

Multiple dynamic FIND_IN_SET searches

So, I have an array like this in my programming language:

And I have a MySQL database table like this:

Unfortunately, I cannot change the table to be more relational (yet).

I want to pull out how many times an item in my array is present in the database value column. Now, the obvious way to do this would be something like:

But there might be dozens of animals to search for, and I don’t want to send a db request per animal. I have thought of the way below, and then using PHP to look at the values to see if the animal is present within… but it’s a bit hacky. Might there be a better way?


ysth’s solution explain‘d

Advertisement

Answer

Join against your list:

You can try forcing it to only read through animal once, I don’t know if that will make it faster or slower:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement