I have a table products (id, barcode, catid, name, description, …) and I’ve been asked to make it possible that some products can be assigned to more than one categories.
The most obvious solution would be to change catid from INT to VARCHAR with delimited values ie 1,2,5 where 1,2 & 5 are the various categories.
Which SQL statement will do the job for me now? I have find_in_set in mind but I think it does the opposite.
The most obvious solution would be to create a ‘cross-table’ where you can do a many-to-many assignment (as in one category can have many products and one product can have many categories). This table would look like this:
You can then use this query:
You can even use normal
WHEREand `ORDER BY, etc.edit: Fixed a major error in my query, my appologies!
If you are unable to change the database, you might want to try this:
Warning: It is a long shot, I haven’t tested this, but as FIND_IN_SET would search a comma-seperated list, it could work.