Skip to content
Advertisement

Fetch rows from a table if their ids are in a serialized value in another table

I want to fetch values from one table (people) if their ids are within the serialized data of another table (groups).

In the table groups I have this row that contains this serialized data stored:

JavaScript

Here’s converted to an array so it’s easier to look at

JavaScript

I have another table, people, that has thousands of rows with data on those people (name, surname, mail), as you can tell from the array I want to fetch specifically the rows whose ids are in that groups’ row (7, 13, 14, 16, 28, 42, 46, 79, 81, 94, 149, 219, 234, 264, 266, 270, 273 and 285).

I’m able to work in PHP with individual values within the table groups easily using this regex code

JavaScript

Let’s say I query this

JavaScript

That will indeed fetch me all the rows in the table groups that contain the id 7.

Now, what I need is to basically get name and surname from my table people but only those whose ids are in that specific data in groups. I’ll write some non functioning code just so you can see my approach

JavaScript

Could you give me a hand? I’m certain regex has to be used and perhaps CASES but I have no experience with those. I want to get everything in a single query if possible.

Advertisement

Answer

You need to join the tables.

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