[英]Update tables in database from tables in a different form
我有一個工作導入XML到我的MySQL,導入到表。 現在,我想用這些導入的表更新我的新表。 但是我不知道如何。
導入程序從3種不同的xml導入。 產品,價格,庫存
它導入到products
, product_descriptions
,圖片等
例:
Products
ID | Name | stock | date
1 | product 1 | 9999 | 2013.07.13
2 | product 2 | ....
Product_description
ID | description | price | date | sale price
1 | product 1... | 1$ | 2013.07.17 | 0$
2 | Product 2 is blabla.. | 999 $ | 2013... | 10$
我想用其他表更新這些項目:
posts
Post ID | post title | description | product ID
100 | products-name | product_description-description | product-ID <- with these item from another tables.
和,
postmeta
post id | meta | value
100 | price | products_description - price
100 | sale price | product_description - sale price
100 | title | products-name
100 | image | imagepath
我不知道該怎么辦。 有人幫我嗎?
您可以使用INSERT INTO ... SELECT構造。
MySQL提供了一本不錯的手冊: http : //dev.mysql.com/doc/refman/5.0/en/insert-select.html
例如,
INSERT INTO posts (post_title, description)
SELECT
Products.Name, Products.stock
FROM Products
這會將產品的所有名稱和庫存級別的所有名稱和庫存級別插入到職位表中
PS我看不到產品和產品說明之間的任何連接。 有外鍵嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.