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'
精彩评论