1

我试图将值插入到表中,其中行的 ID 只能通过在另一个表上执行 SELECT WHERE 来找到。以下是我的查询:

INSERT INTO wp_postmeta (meta_key, meta_value) 
VALUES ('editor_review','5') 
WHERE post_id=(SELECT ID from wp_posts 
               WHERE post_title 
              LIKE "%The Honest Kitchen ZEAL Grain Free Gluten Free All Life Stages Dog Food%");

有什么想法吗?

谢谢

4

2 回答 2

0
INSERT INTO wp_postmeta
    (post_id, meta_key, meta_value)
    SELECT id, 'editor_review', '5'
        FROM wp_posts
        WHERE post_title LIKE '%The Honest Kitchen ZEAL Grain Free Gluten Free All Life Stages Dog Food%'
于 2012-09-11T15:54:43.547 回答
0

您可以INSERT INTO...SELECT为此使用语句。

INSERT INTO wp_postmeta (meta_key, meta_value) 
SELECT colA, colB
FROM wp_posts 
WHERE post_title 
LIKE "%The Honest Kitchen ZEAL Grain Free Gluten Free All Life Stages Dog Food%"

注意列数必须相互匹配(也是它们的数据类型)

于 2012-09-11T15:54:52.797 回答