开发者

MySql - Inserting multiple rows with a joined subquery?

This query will return a list of project IDs that represent forum threads:

SELECT id FROM `proj_objects` WHERE  type='fthread';

This query will subscribe a user (whose ID in the users table is '37') to the forum thread wi开发者_运维技巧th an ID of '122':

INSERT INTO `subscrips` VALUES ( 37, 122 ) ;

I'd like to insert multiple rows that will subscribe user 37 to all project objects where type is fthread. Can I do this in a single query?


Use:

INSERT INTO `subscrips` 
SELECT 37, id 
  FROM `proj_objects` 
 WHERE type = 'fthread'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜