In my MySQL products table there is a column called groups which products can belong to. What is actually stored in this column are id’s of another tabled called groups.
What if I want to select products that belong to a specific group?
If a product can only belong to a single group, I could simply use
where group={groupid}
But what if a product can belong to multiple groups?
I could store them like this: ‘4,8,10,42‘, each of these numbers meaning a group id.
But then how would I query a select?
You should not store a list of products in a single field. Instead of a column
products.groups, you should have a separate tableproduct_groups (product_id, group_id), where you store each association between a product and a group. Then you can select all products from a group as this: