开发者

select more rows as a column

开发者 https://www.devze.com 2022-12-29 18:38 出处:网络
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

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 ?


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  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号