开发者

MySql - Inserting multiple rows with a joined subquery?

开发者 https://www.devze.com 2023-01-12 00:57 出处:网络
This query will return a list of project IDs that represent forum threads: SELECT id FROM `proj_objects` WHEREtype=\'fthread\';

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

精彩评论

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