MySQL Forums
Forum List  »  Newbie

Re: How to join two rows in same table?
Posted by: Felix Geerinckx
Date: June 17, 2005 02:42AM

sooeydoo wrote:

> I have two rows - heading and body - in one table tiki_articles

Do you mean 'two columns'?

> While all rows have heading, only some have body. I want to combine those rows that have a body
> with their corresponding heading rows so that the result is one big heading row with both heading
> and body content in that order.


UPDATE tiki_articles SET heading = CONCAT(heading, 'some spacer', body)
WHERE body IS NOT NULL;


But be careful:

1) there is no way back
2) make sure the combined header/body fits in the header column, or truncation will occur.

It's probably best to try this first on a copy of the table, or to use ALTER TABLE to add another column and put the combined header/body in that column:

ALTER TABLE tiki_articles ADD COLUMN headingbody TEXT;
UPDATE tiki_articles SET headingbody = CONCAT(heading, 'some spacer', body)
WHERE body IS NOT NULL;

When everything is OK (no warnings) you can then remove the heading and body columns and rename the headingbody column back to heading (if that is what you want).

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: How to join two rows in same table?
June 17, 2005 02:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.