MySQL——将数据从一个表复制到另一个表

时间:2022-06-01 18:39:21

I'm trying to copy the data from one row and create a new one with some of the values.

我正在尝试从一行中复制数据,并使用一些值创建一个新的数据。

I think I have it basically working BUT I want to set value of meta_key to additional_articles_0_article_url, and not copy the value "articles"

我想我已经设置好了但是我想把meta_key设置为additional_articles_0_article_url,而不是复制"articles"

And after that occurs, create new row, with using the same post_id?

然后使用相同的post_id创建新行?

Any ideas?

什么好主意吗?

INSERT INTO tpl_postmeta (post_id, meta_key, meta_value)
SELECT m.post_id, m.meta_key, m.meta_value
FROM tpl_postmeta m
WHERE m.meta_key = "articles" AND m.meta_value LIKE "%.com%";

INSERT INTO tpl_postmeta(post_id, meta_key, meta_value) 
VALUES ('same post_id as above','_additional_articles_0_article_title', 'New Article')

1 个解决方案

#1


2  

I think you just want this:

我想你就是想这样:

INSERT INTO tpl_postmeta (post_id, meta_key, meta_value)
    SELECT m.post_id, 'additional_articles_0_article_url', m.meta_value
    FROM tpl_postmeta m
    WHERE m.meta_key = "articles" AND m.meta_value LIKE "%.com%";

#1


2  

I think you just want this:

我想你就是想这样:

INSERT INTO tpl_postmeta (post_id, meta_key, meta_value)
    SELECT m.post_id, 'additional_articles_0_article_url', m.meta_value
    FROM tpl_postmeta m
    WHERE m.meta_key = "articles" AND m.meta_value LIKE "%.com%";