tags:

views:

73

answers:

2

Hi,

I have a "Groups" table and a "Participants" table. Now I need to insert one Participant for each Group. How would I automate this?

INSERT INTO "Participants" ("Name", "FirstName", "GroupID") VALUES ("GENERIC", "GENERIC", GroupID)

This Insert should be called for each Group in the Groups table, and the "GroupID" replaced with the corresponding ID.

Would this work with a subquery?

Thanks, martin

+1  A: 
INSERT INTO `Participants`
SELECT ("Name", "FirstName", `group_id`)
FROM `Group`
Zed
+1  A: 

INSERT INTO SELECT...

INSERT INTO
 Participants
(
 Name,
 FirstName,
 GroupID
)
SELECT
 'GENERIC',
 'GENERIC',
 GroupID
FROM
 Groups
Robin Day
Thanks, works perfectly!!
Martin