tags:

views:

191

answers:

2

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 ::. thx, Greg. But...

GROUP_CONCAT() --> The same output like concat(). Only one name per "Anlass". But i need, Multiple names comma separated for one "Anlass".

mhmm... Sitting on this Problem since yesterday ;) I will have weekend...

.:: 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
+1  A: 

I think you're looking for GROUP_CONCAT. You should also group by something:

SELECT GROUP_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 ZuwAnlID = Anlass.AnlID
GROUP BY ?
Greg
Its the Same Output, only One Name in a row.I have a table "parameter_zuweisung_anl" with ID's from "anlass" and "Beziehung"."Beziehung" has a column with a Name. This Name must linked to the "Anlass".
d4workz
did you GROUP BY Anlass.AnlID?
Greg
hi, thx for yor spended time ;)it was not "WHERE ZuwAnlID = Anlass.AnlID" i've corrected them.This is the right one "WHERE ZuwAnlAnlNr = Anlass.AnlID".But yet, mysql gave me an Error like: Subquery returns more than 1 row.mhmm, ALL or ANY Dont work ?!
d4workz
ui, it works ;)Many thx, and a nice weekend.
d4workz
A: 

Ok, it works with this query:

SELECT  GROUP_CONCAT(BeziehKuBez) AS Ausgabe
    FROM `stammdaten_beziehungen` AS Beziehung
    INNER JOIN `parameter_zuweisungen_anl` ON  Beziehung.BeziehID = parameter_zuweisungen_anl.ZuwAnlBeziehID
    WHERE ZuwAnlAnlNr = Anlass.AnlID
    GROUP BY ZuwAnlAnlNr

Many thx to greg. My Weekend is now rescued ;)

d4workz