2012-09-11 54 views
1

進出口試圖將值插入一個表,其中的行的ID只能由WHERE上另一表執行SELECT被發現。以下是我的查詢:MySQL的INSERT 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%"); 

任何想法做到這一點?

感謝

回答

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%' 
+0

謝謝喬匹配 - 這完美! – user1663381

+0

@ user1663381:很高興提供幫助。 –

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

注意,列數必須與對方(也是他們的數據類型)