从mysql中的字段中删除重复的单词 [英] Remove duplicate words from field in mysql

查看:157
本文介绍了从mysql中的字段中删除重复的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用mysql查询从一个字段中删除重复的文本,或者是否可以使用PHP更好地解决这样的问题.

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 database where users enter tags which can be searched upon. I have noticed that some tags have synonyms which I want to add to the field, but in some cases the synonym already exists, in other cases not. For example after I have updated the tags, I can end up with the following (the tags are separated by spaces only):-

  1. 泳池游泳池海洋海水
  2. 游泳海洋海水水游泳
  3. 游泳池游泳游泳池游泳

是否有一种方法可以消除同一字段中的重复文本,所以我最终做到了这一点?

Is there a way to eliminate duplicate text from the same field so I end up with this?

  1. 泳池游泳海洋海水游泳
  2. 海洋海水游泳
  3. 泳池游泳

推荐答案

您描述的模型(所有标签放入单个单元格,以空格分隔)未标准化,因此您无法期望找到简单,高效且可靠的模型从数据库服务器处理数据的方法(除了阅读专栏之外).到目前为止,PHP是您计划进行清理的唯一机会,而且您必须检索每一行.

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.

现在对数据库设计进行一些更改是否为时已晚?如果将每个标签存储在tag表的单独一行中,则可以使用普通SQL进行很多操作.

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.

这篇关于从mysql中的字段中删除重复的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆