Reputation: 25
I have a problem I don't know how to add a new line to a table. I just wish to add one more line with the same ID_Group but with different ID_item. I have a column named ID_group with id from 1 to 230 and each ID_group have 7 lines (query below). Now i need to add a 8th line to each ID_group because there's a new id_item that is 7 (logically) This query only shows what I'm talking about
id_group id_item
9 0
9 1
9 2
9 3
9 4
9 5
9 6
10 0
10 1
10 2
10 3
10 4
10 5
10 6
11 0
11 1
11 2
11 3
11 4
11 5
11 6
13 0
13 1
13 2
13 3
13 4
13 5
13 6
Can you help me?
One more thing. I'm new to SQL and development so sorry for any stupid question.
Upvotes: 1
Views: 239
Reputation: 495
Assuming T-SQL and that I understand you're trying to add an id_item 7 for each existing id_group, this should do it:
INSERT INTO [tablename] (id_group,id_item)
SELECT DISTINCT id_group,7
FROM [tablename];
You'll have to substitute the actual table name for [tablename]
.
Upvotes: 2
Reputation: 96552
Insert MyTable (Id_group, ID_Item)
select distinct Id_group,7 from MyTable
Upvotes: 2