Transfer multiple rows from 1 table to another
I created a new table named Rate for rating posts from my Posts table. The Posts table already has data but Rate is empty. When I create a new post, its ID is added to Rate but there are many posts not added that were开发者_StackOverflow中文版 published before the Rate table.
What sort of query can I use to transfer multiple rows from Posts (just the ids) to the Rate table?
Use the MySQL INSERT ... SELECT
for inserting data from one table to another. e.g.:
INSERT INTO Rate (ID, col1, col2) SELECT ID, somecol1, somecol2 FROM Posts WHERE ....
精彩评论