Subquery returns more than 1 row solution for update query using select statement

后端 未结 2 1259

Hello i have query in which i have written update statement using select statement. But unfortunately getting errors subquery returns more than 1 row. I know where the error is

2条回答
  •  被撕碎了的回忆
    2021-01-24 13:03

    When you use update with SET configuration=(SELECT ...) the subquery has to return no more than one value (one row). If it returns more than one value how do you assign two rows table for example to scalar configuration field. So you should figure out WHY your subquery returns more than one row and fix the subquery or decide which ONE value to select for update in case of more than one row. For example you can select maximum value

    SELECT MAX(ad_news_texte.headline)...
    

    or any one first value

    (SELECT ad_news_texte.headline)... LIMIT 1)
    

    and so on...

    If you need to concatenate all rows and put it into one row configureation you can use GROUP_CONCAT() mysql function:

    SET configuration=(SELECT GROUP_CONCAT(DISTINCT ad_news_texte.headline) FROM ....
    

提交回复
热议问题