2

我想将一些行数据复制到另一个表中,例如:

我有这2 个表:( qa_items_purchases), ( qa_suppliers_invoices)

qa_items_purchases, 数据:

在此处输入图像描述

qa_suppliers_invoices是空的:

在此处输入图像描述

我需要复制表 (qa_items_purchases) 中包含的所有记录,仅提取另一个表具有的字段。

编辑: 在表格之间,名称会有所不同:

purchase_code AS itempurchase_code
supplier_invoice_code AS item_invoicecodesupplier
supploer_invoice_date as itempurchase_date
4

2 回答 2

2

试试这个:

INSERT INTO qa_suppliers_invoices (purchase_code,supplier_code, user_code, status_code, supplier_invoice_code,supplier_invoice_date)

SELECT itempurchase_code,supplier_code, user_code, status_code,item_invoicecodesupplier,itempurchase_date FROM qa_items_purchases
于 2012-07-10T17:40:36.900 回答
1

插入选择手册,访问 http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

insert into qa_suppliers_invoices 
(purchase_code, supplier_invoice_code, supploer_invoice_date )
SELECT itempurchase_code, item_invoicecodesupplier, itempurchase_date
FROM qa_items_purchases

如果您需要更多列,只需添加列。cols 顺序很重要。

于 2012-07-10T18:07:50.667 回答