tags:

views:

446

answers:

2

I have a table posts that could look like this:

  id  |  title  |  body  |  created  | ..
-------------------------------------------

I would like to use the boolean search feature that is offered by a MyISAM Table, but the posts table is InnoDB. So I created another table 'post_contents' that looks like this:

  post_id  |  body
--------------------

That table is already filled with some contents and I can use the boolean search. However, I need to move the title field in the post_contents table as well and then copy the existing title-data to the new field.

I know about the INSERT .. SELECT syntax, but I don't seem to be able to create the correct query.

+1  A: 

Did you try

insert into post_contents (post_id, body) select id, body from posts;

Or is the post_id column in the post_contents table generated differently?

MJB
Thanks for the quick answer. I just tried that, but i get a `#1062 - Duplicate entry '1' for key 'PRIMARY'`The body field does already exist and is filled in the new table (I want to add the title field), so I probably need an UPDATE query?!
harpax
Sorry, I couldn't tell from your question that the second table already had data that you had to match up to.
MJB
my bad .. I have difficulties to express myself in english :) Your answer still led me in the right direction -> thanks
harpax
A: 

I found a way:

I copied the the post_contents table to pc and truncated the existing data in post_contents. Then I used that query

INSERT INTO post_contents (post_id, title, body, created, modified) 
SELECT post.id, post.title, pc.body, pc.draft, pc.created, pc.modified 
FROM posts 
INNER JOIN pc ON post.id = pc.post_id

Maybe that is helpful for other people :)

harpax