开发者

SQL insert a foreach select on same table?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜