开发者

SQL insert a foreach select on same table?

开发者 https://www.devze.com 2023-03-10 13:48 出处:网络
Can I, instead of doing this via PHP, combine this in 1 sql statement? object_ids = \"select object_id from `wp_term_relationships` where `term_taxonomy_id` = 14;\";

Can I, instead of doing this via PHP, combine this in 1 sql statement?

object_ids = "select object_id from `wp_term_relationships` where `term_taxonomy_id` = 14;";
foreach(object_ids as object_id) 
{
    "insert into `wp_term_relationships` VALUES (" . object_id . ",1597,0);";
}

(for WordPress: for every post 开发者_如何学编程that has a category (14) add a new term relationship (1597))


INSERT INTO `wp_term_relationships`
SELECT object_id, 1597, 0
FROM `wp_term_relationships`
WHERE `term_taxonomy_id` = 14;


Better something like:

 INSERT INTO wp_term_relationships
 SELECT  object_id, 1597, 0
 FROM wp_term_relationships
 WHERE term_taxonomy_id = 14
0

精彩评论

暂无评论...
验证码 换一张
取 消