联合数据库中的列

时间:2018-04-05 06:51:31

标签: mysql sql database ms-access

我有一个字典数据库。 它有3列。

ID , word ,meaning
  • 1 = landscape = meaning1
  • 2 = landscape = meaning2
  • 3 = landscape = meaning3
  • 4 = landscape = meaning4
  • 5 = landscape = meaning5
  • 6 =光泽= mean1
  • 7 = glossy = mean2
  • 8 = glossy = mean3
  • 9 = glossy = mean4

我如何结合这样的词的含义:

  • 1 = landscape = meaning1,含义2,含义3,含义4,含义5
  • 2 = landscape = mean1,mean2,mean3,mean4

2 个答案:

答案 0 :(得分:1)

您可以GROUP BY将其作为

SELECT id, word, GROUP_CONCAT(meaning ORDER BY meaning)
FROM tbl_name
GROUP BY word

对于大量值,GROUP_CONCAT将从末尾截断值。要处理此问题,请在执行查询之前设置group concat max len

SET SESSION GROUP_CONCAT_MAX_LEN=1000000

答案 1 :(得分:0)

您正在寻找GROUP_CONCAT功能:

SELECT
    word,
    GROUP_CONCAT(meaning ORDER BY meaning)
FROM yourTable
GROUP BY
     word;

enter image description here

Demo