I have a mysql table, each row of which can have an arbitrary number of comma-delimmited words. For example:
TABLE words
"test, dog, fun, yellow, quick, yellow"
"jogging, academic, fun, jogging, shoulder"
"shoulder, happy, flower, shoulder, shoulder"
I would like to remove the duplicate words in each row. So for example, the above would become:
TABLE words
"test, dog, fun, yellow, quick"
"jogging, academic, fun, shoulder"
"shoulder, happy, flower"
(Note that I only need to remove the duplicates in each row, by itself. I do not need to remove the duplicates between all rows.)
Any suggestions on the best way to accomplish this? Is there a better way than SELECTing and then UPDATEing through the table one row at a time?
Thanks, in advance, for your help.
This is better suited outside of SQL. It’s not going to be pretty if you try to interrogate strings using a query. I recommend:
SELECTing each row$val = explode(', ',$column);$val = array_unique($val);, thenUPDATEing to the table with implode(‘, ‘,$val);`.note: you can save yourself some time and do a
strcmp($orig,$new)and onlyUPDATEif necessary.