1
Answer

same ID different rows in sql

darma teja

darma teja

10y
631
1
Hi All,

I want to insert 500 rows in the table.

table has ID, groupID,  name, firstname

My data is like this:

I have  groupIDs: 1,2,3

I have 500 rows of name and firstname.

I want to insert these 500 rows of name and firstname for every gorupID

I wrote like this:

insert into table (groupID,  name, firstname)
SELECT 1, 'a', 'b' union all
SELECT 1, 'c', 'd' union all
SELECT 1, 'e', 'f' union all

But it is difficult to write groupID everytime. Is there any solution?

Many thanks,
Darma

Answers (1)