MySQL 删除一个 link table 并将 3 table 合并为一个
MySQL removing a link table and joining 3 tables into one
我有一个数据库,其中有一个无关的数据库 table,用于通过 djangocms 占位符字段添加的产品文本内容。我希望将此内容移回单个 table.
我的三个 table 是:
products_product:
+------------+------------+
| product_id | content_id |
+------------+------------+
| 374 | 1919 |
+------------+------------+
cms_cmsplugin:
+----------------+------+
| placeholder_id | id |
+----------------+------+
| 1919 | 2042 |
+----------------+------+
和cmsplugin_text:
+------------------+------------------+
| cmsplugin_ptr_id | body |
+------------------+------------------+
| 2042 | <p>some_html</p> |
+------------------+------------------+
我希望删除 link table 并将 cmsplugin_text 正文直接添加到 products_product table 中,字段名称为 text_content。到目前为止,我一直在查看 this 个问题并得出以下结论:
INSERT INTO
products_product(content_id, text_content)
SELECT
p.content_id,
cpt.body as text_content
FROM products_product p
JOIN cms_cmsplugin cms ON p.content_id = cms.placeholder_id
LEFT JOIN cmsplugin_text cpt ON cms.id = cpt.cmsplugin_ptr_id
不幸的是,这没有用,只是把我的 products_product table.
搞得一团糟
在 products_product 更新中添加列后:
UPDATE products, cms_cmsplugin, cmsplugin_text
SET products.body = cmsplugin_text.body
WHERE product.content_id = cmsplugin_text.placeholder_id
AND cmsplugin_text.id = cmsplugin_ptr_id
我有一个数据库,其中有一个无关的数据库 table,用于通过 djangocms 占位符字段添加的产品文本内容。我希望将此内容移回单个 table.
我的三个 table 是:
products_product:
+------------+------------+
| product_id | content_id |
+------------+------------+
| 374 | 1919 |
+------------+------------+
cms_cmsplugin:
+----------------+------+
| placeholder_id | id |
+----------------+------+
| 1919 | 2042 |
+----------------+------+
和cmsplugin_text:
+------------------+------------------+
| cmsplugin_ptr_id | body |
+------------------+------------------+
| 2042 | <p>some_html</p> |
+------------------+------------------+
我希望删除 link table 并将 cmsplugin_text 正文直接添加到 products_product table 中,字段名称为 text_content。到目前为止,我一直在查看 this 个问题并得出以下结论:
INSERT INTO
products_product(content_id, text_content)
SELECT
p.content_id,
cpt.body as text_content
FROM products_product p
JOIN cms_cmsplugin cms ON p.content_id = cms.placeholder_id
LEFT JOIN cmsplugin_text cpt ON cms.id = cpt.cmsplugin_ptr_id
不幸的是,这没有用,只是把我的 products_product table.
搞得一团糟在 products_product 更新中添加列后:
UPDATE products, cms_cmsplugin, cmsplugin_text
SET products.body = cmsplugin_text.body
WHERE product.content_id = cmsplugin_text.placeholder_id
AND cmsplugin_text.id = cmsplugin_ptr_id