Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select more rows as a column

I have a MySQL issue

i want to have the result of the next query into a var and use it to update into the trigger i am trying to get the names comma separated

The query returns more then one row

SELECT t.naam
FROM    trefwoorden t
INNER JOIN organisaties_has_trefwoorden AS o ON (t.id_trefwoorden = o.id_trefwoorden)
WHERE   o.id_organisaties = NEW.id_organisaties;

Here is the trigger

CREATE TRIGGER updCheck_After AFTER
UPDATE ON organisaties_has_trefwoorden 
FOR EACH row    

    UPDATE organisaties o
    SET    o.trefwoorden_flat = 
    (
        SELECT t.naam
        FROM    trefwoorden t
        INNER JOIN organisaties_has_trefwoorden AS o ON (t.id_trefwoorden = o.id_trefwoorden)
        WHERE   o.id_organisaties = NEW.id_organisaties;        
    )
    WHERE  o.id_organisaties = NEW.id_organisaties  

The question is it possible to select more rows as 1 column comma separated or is there a other solution ?

someone a suggestion ?

like image 779
Marco Avatar asked Mar 04 '26 01:03

Marco


1 Answers

UPDATE  organisaties o
SET     o.trefwoorden_flat = 
        (
        SELECT  GROUP_CONCAT(t.naam SEPARATOR ',')
        FROM    trefwoorden t
        INNER JOIN
                organisaties_has_trefwoorden AS o
        ON      t.id_trefwoorden = o.id_trefwoorden
        WHERE   o.id_organisaties = NEW.id_organisaties       
        )
WHERE   o.id_organisaties = NEW.id_organisaties  
like image 147
Quassnoi Avatar answered Mar 05 '26 15:03

Quassnoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!