【发布时间】:2017-03-10 03:57:43
【问题描述】:
我有一个 MySQL 表,它有三列,第一列是唯一键 (INT(11) AUTO_INCREMENT),接下来是索引值 (VARCHAR(255)),第三列是描述 (TEXT)。第二列有重复值,但每一行都有不同的描述。我想删除第二列重复的所有行,但将相同索引值的每个描述附加到第一个实例的值,并用分号和空格分隔字符串。
例如,我的表是这样的:
cid | word | description
------------------------------
1 | cat | an animal with wiskers
2 | cat | a house pet
3 | dog | a member of the canine family
4 | cat | a cool person
我想把表格改成这样:
cid | word | description
------------------------------
1 | cat | an animal with wiskers; a house pet; a cool person
3 | dog | a member of the canine family
我不反对使用 PHP 脚本来执行此操作,但我更喜欢 MySQL。该表有超过 170,000 行,PHP 需要很长时间才能遍历它。
【问题讨论】:
-
MySQL 5.7 会在此处抱怨
cid,因为您选择该数字的方式没有逻辑。它是最低的cid值吗?可以在您的备用视图中省略该列吗?