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

时间:2015-05-06 21:05:21

标签: mysql sql database

我试图从一行复制数据并创建一个包含一些值的新数据。

我认为我基本上工作但我想将meta_key的值设置为additional_articles_0_article_url,而不是复制值"文章"

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

有什么想法吗?

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 个答案:

答案 0 :(得分:2)

我想你只想要这个:

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%";