Mysql Multiple Concat Inner Join,只给出一个Name
我有三张桌子。
table1 = anlass table2 = stammdaten_beziehungen table3 = parameter_zuweisungen_anl
它给了我这个错误:子查询返回超过 1 行
但我需要的是所有'BeziehKuBez'逗号分隔在一列中。
例如。 Beziehname1、Beziehname2、...
如果已使用 CONCAT_WS(',', BeziehKuBez)
进行测试。但给我一样的。我可以用 while 循环来做到这一点吗?但我不知道怎么办?!
更新: 关于Greg的回答:
GROUP_CONCAT()
提供与 concat()
相同的输出。
每个“Anlass”只有一个名字。但我需要,用逗号分隔一个“Anlass”的多个名称。
表结构:
表 Anlass:
AnlID、anlass_name
表 Stammdaten_beziehungen
BeziehID、Beziehkubez
表 Parameter_zuweisung_anl
ZuwAnlID、ZuwAnlAnlNr、ZuwAnlBeziehID
<强>信息 ZuwAnlAnlNr 链接到 Anlass.AnlID ZuwAnlBeziehID 链接到 Beziehung.BeziehID
这是我的查询:
SELECT CONCAT(`BeziehKuBez`) AS Bezname
FROM `stammdaten_beziehungen` AS Beziehung, `anlass` AS anlass
INNER JOIN `parameter_zuweisungen_anl`
ON Beziehung.BeziehID = parameter_zuweisungen_anl.ZuwAnlBeziehID
WHERE ZuwAnlAnlNr = Anlass.AnlID
I have three Tables.
table1 = anlass table2 = stammdaten_beziehungen table3 = parameter_zuweisungen_anl
It gaves me this ERROR: Subquery returns more than 1 row
But what i need, is all 'BeziehKuBez' Comma separated in one column.
eg. Beziehname1, Beziehname2, ...
If have test it with, CONCAT_WS(',', BeziehKuBez)
. But give me the same one. Could I do this with a while loop? But I dont know how?!
Update:
Regarding Greg's answer:
GROUP_CONCAT()
gives he same output as concat()
.
Only one name per "Anlass". But i need, Multiple names comma separated for one "Anlass".
TABLE STRUCTURE:
Table Anlass:
AnlID, anlass_name
Table Stammdaten_beziehungen
BeziehID, Beziehkubez
Table Parameter_zuweisung_anl
ZuwAnlID, ZuwAnlAnlNr,ZuwAnlBeziehID
INFO
ZuwAnlAnlNr linked to Anlass.AnlID
ZuwAnlBeziehID linked to Beziehung.BeziehID
This is my query:
SELECT CONCAT(`BeziehKuBez`) AS Bezname
FROM `stammdaten_beziehungen` AS Beziehung, `anlass` AS anlass
INNER JOIN `parameter_zuweisungen_anl`
ON Beziehung.BeziehID = parameter_zuweisungen_anl.ZuwAnlBeziehID
WHERE ZuwAnlAnlNr = Anlass.AnlID
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找 GROUP_CONCAT 。您还应该按某些内容进行分组:
I think you're looking for GROUP_CONCAT. You should also group by something: