Insert multiple rows into a junction table with INSERT SELECT

I am trying to populate a junction table, testimonialTopics, so that I can quickly assign a topic to multiple testimonials at once, if they meet the right criteria. I’ve googled the best way to do this and the following are examples that ranked well on StackOverflow. Unfortunately, both examples produce an error, “Subquery returns more than 1 row”. My junction table only has two columns, testimonialID, topicID. The topicID of 2, shown in my examples, correlates to “pinkeye” in the topics table. Does anyone have some helpful ideas?

Thanks!

# First Attempt
INSERT INTO 
	testimonialTopics 
SET
	testimonialID = (SELECT testimonialID FROM testimonials WHERE title like '%pinkeye%'),
	topicID = '2';

# Second Attempt
INSERT INTO
	testimonialTopics 
VALUES (
	(SELECT testimonialID FROM testimonials WHERE title like '%pinkeye%'), 
	'2'
);

INSERT INTO testimonialTopics ( testimonialID , topicID ) SELECT testimonialID , 2 FROM testimonials WHERE title like '%pinkeye%'

This works perfectly! Thanks r937!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.