{"id":2582,"date":"2022-03-26T08:47:52","date_gmt":"2022-03-26T07:47:52","guid":{"rendered":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2582"},"modified":"2022-03-26T08:49:00","modified_gmt":"2022-03-26T07:49:00","slug":"add-some-string-to-several-rows","status":"publish","type":"post","link":"https:\/\/digitalia.culturanuova.net\/blog\/?p=2582","title":{"rendered":"mysql add some string to several rows"},"content":{"rendered":"\n<p>If a column has several rows, i.g.:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'red'  \n'NULL'  \n'red, yellow'  \n'green'  \n'NULL'  \n'yellow, green'\n<\/pre>\n\n\n\n<p>And you want to add a new string (\u2018blue\u2019) to every row, so that the result be:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'red, blue'  \n'blue'  \n'red, yellow, blue'  \n'green, blue'  \n'blue'  \n'yellow, green, blue'\n<\/pre>\n\n\n\n<p>you can use this code<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UPDATE my_table \nSET mycolumn = CONCAT('same new string ',mycolumn); <\/pre>\n\n\n\n<p>But the above code works only for rows with some content, not for the empty (NULL) ones. Therefore you can complete your task with the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">UPDATE my_table \nSET mycolumn = 'same new string' \nWHERE mycolumn IS NULL; <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If a column has several rows, i.g.: &#8216;red&#8217; &#8216;NULL&#8217; &#8216;red, yellow&#8217; &#8216;green&#8217; &#8216;NULL&#8217; &#8216;yellow, green&#8217; And you want to add a new string (\u2018blue\u2019) to every row, so that the result be: &#8216;red, blue&#8217; &#8216;blue&#8217; &#8216;red, yellow, blue&#8217; &#8216;green, blue&#8217; &#8216;blue&#8217; &#8216;yellow, green, blue&#8217; you can use this code UPDATE my_table SET mycolumn = CONCAT(&#8216;same &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/digitalia.culturanuova.net\/blog\/?p=2582\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;mysql add some string to several rows&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[579],"tags":[746,11],"class_list":["post-2582","post","type-post","status-publish","format-standard","hentry","category-database","tag-add-string","tag-mysql"],"_links":{"self":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2582"}],"version-history":[{"count":3,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2582\/revisions"}],"predecessor-version":[{"id":2585,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2582\/revisions\/2585"}],"wp:attachment":[{"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalia.culturanuova.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}