我的SQL看起来像这样:
SELECT GROUP_CONCAT(technologies.tech) AS technologies, personal.city, GROUP_CONCAT(languages.language) AS languages
FROM personal
INNER JOIN technologies ON technologies.uid = personal.uid
INNER JOIN languages ON languages.uid = personal.uid
WHERE personal.uid = 88
结果:
| technologies | city | languages |
|---------------------|:--------------:|-------------------------:|
| PHP,HTML,JavaScript | Chicago | English,English,English |
您看到English
不断重复。如何使它只出现一次?
答案 0 :(得分:1)
您有一个聚合查询,其中SELECT
中有未聚合的列,而没有GROUP BY
。我建议:
SELECT GROUP_CONCAT(DISTINCTt.tech) AS technologies, p.city,
GROUP_CONCAT(DISTINCT l.language) AS languages
FROM personal p INNER JOIN
technologies t
ON t.uid = p.uid INNER JOIN
languages l
ON l.uid = p.uid
WHERE p.uid = 88
GROUP BY p.city;
注意:
GROUP_CONCAT(DISTINCT)
回答您的问题p.city
放在SELECT
中。 MySQL的最新版本会抱怨。所以我添加了GROUP BY
。