Remove duplicate words from field in mysql

后端 未结 6 509
囚心锁ツ
囚心锁ツ 2021-01-21 03:02

I am wondering if it is possible to remove duplicate text using a mysql query from one field, or if a problem like this would be better solved using PHP.

I have a databa

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 03:08

    The model you describe (all tags into a single cell, separated by spaces) is not normalized so you can't expect to find a simple, performant and reliable way to do stuff with it from the database server (beyond reading the column). The way it's now, PHP is your only chance to do the cleanup you are planning to do, and you'll have to retrieve every row.

    Is it too late to make a little change in the database design? If you store each tag into a separate row in a tag table you'd be able to do lots of stuff from plain SQL.

提交回复
热议问题