Forum Moderators: open
INSERT INTO destination-table (content)
SELECT table1 FROM content;
INSERT INTO destination-table (titles)
SELECT table2 FROM titles;
Here's my situation, I currently have an article directory and I want to move the articles over to a new database. The current database stores the titles of the articles in one table and the article body in another table. The new database stores titles and body in one table using separate columns. I want to move article body from table 1 and titles from table 2 into the new database.
This is what happens when using the above method.
Rows
1 content
2 content
3 content
4 titles
5 titles
6 titles
The information goes into the right columns but the titles and content don't match because the titles are placed in newly created rows. So lets say I have 50 articles, the content is found in row 1 - 50 and the titles are found in rows 51 - 100.
How can I successfully have titles and content in the same rows?
I'm new to MySQL databases. Thank you for your time and patiece. :)
insert into new_table select columns-in-new-order from old_table;
so something like
insert into new_table (content,titles) values (select content.txt,titles.txt from content, titles where content.id=titles.content_id);
The previous probably has syntax errors, but that's the general approach.
If you can't work out a single statement, you'd have to do it with loops in programming, making sure the titles.content_id is associated with the corresponding content.id.