复制mysql中不同表中有关系的记录


Copy records in mysql with relationships in different tables

我有3个不同的表。它们通过表中的ID列相互连接。

table "Purchase"
table "Catalog" has 'purchase_id' column in table
table "Product" has 'catalog_id' column in its table.

如何在一键复制记录一些已经激活的"购买"与它所包含的所有目录和产品?

看起来像这个帖子重复的记录在MySQL或多或少连接。怎么做呢?

Do and 'insert select':

  insert into <table> ( purchase_id, catalog_id, product_id ) 
     select purchase_id, catalog_id, product_id from Purchase 
       join Catalog using ( purchase_id )
       join Product using ( catalog_id )
   where <some condition>;