Im trying to insert values into a table where the ID of the row can only be found by performing a SELECT WHERE on another table. Below is my query:
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%");
Any ideas to do this?
Thanks
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%'
You can use INSERT INTO...SELECT
statement for that.
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%"
NOTE That the number of columns must match with each other (also their datatypes)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.