简体   繁体   English

将多行从一张表转移到另一张表

[英]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 published before the Rate table. 当我创建新帖子时,其ID被添加到Rate中,但是在Rate表之前发布了许多未添加的帖子。

What sort of query can I use to transfer multiple rows from Posts (just the ids) to the Rate table? 我可以使用哪种查询将多个行从“帖子”(仅是ID)转移到“费率”表?

Use the MySQL INSERT ... SELECT for inserting data from one table to another. 使用MySQL INSERT ... SELECT将数据从一个表插入到另一个表。 eg: 例如:

 INSERT INTO Rate (ID, col1, col2) SELECT ID, somecol1, somecol2 FROM Posts WHERE ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM