[CS-FSLUG] Moving things around in SQL

Robert Wohlfarth rbwohlfarth at gmail.com
Mon Nov 19 11:14:56 CST 2012


On Sat, Nov 17, 2012 at 10:55 PM, Timothy Butler <tbutler at ofb.biz> wrote:

> Hello, friends,
>         Let's say I have two columns in MySQL named body and extbody. Is
> there any easy way, entirely within a SQL query to take everything in
> extbody and append it to the existing body column for every row in the
> table? I've rethought the way I want to structure a MySQL table for a web
> app I've been working on and need to rapidly move the data around in four
> or five different installations, so doing so entirely in a self-contained
> query would make it a lot faster process...
>

Do you mean something like this?
UPDATE table SET body = CONCAT(COALESCE(body,''), COALESCE(extbody,''))

If you want the extended text to start on the next line, it could be
something like this:
UPDATE table SET body = CONCAT_WS(CHAR(10), COALESCE(body,''),
COALESCE(extbody,''))

-- 
Robert Wohlfarth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ofb.biz/pipermail/christiansource_ofb.biz/attachments/20121119/cb75f975/attachment.htm>


More information about the Christiansource mailing list