For example, a column in a candy store database contains a list of flavors that the different shapes of candy come in. We have another table of flavors, but rather than a third relative table of flavors and product relationships, the IDs of the flavors are simply stored in a column in the products table.

So, you might have a value like 12,14,35,36,78,105 where each number represents the value of a form checkbox in the product admin for this site, and and ID for a flavor in the flavors table. The store admin checks the boxes for the flavors that product comes in, and those IDs get stored as a list in a specific column.

For the purpose of example, suppose the column is simply called 'flavors', and you need to add the flavor 'wowzaberry' (id 199) to all of the products that currently have the flavor 'razzoberry' (id 105) - with the added logic so that if a candy product already has the new flavor, we don't add it twice.

view plain print about
1UPDATE tbl_products
2SET flavors = CONCAT(flavors,',199')
3WHERE FIND_IN_SET('105',flavors)
4AND NOT FIND_IN_SET('199',flavors)

This says Add (concat) a comma (,) and 199 (the new ID number) To any record that already has ID 105 in the flavors column And that does not already have ID 199 in that same column