I have 2 tables:
Table T1
Id Test Question
-----------------
1 Test1 Q
2 Test2 Q
3 Test3 Q
Table T2
ID T1_ID Ans
------------
1 1 A1
2 1 A2
3 2 B1
4 2 B2
5 2 B3
6 3 C1
7 3 C2
I am inserting T1 values using select
statement with different question value
Insert into T1 (Test, Question)
Select Test, 'P' From T1
Similarly I want to copy data of T2, T1.Id should be newly generated id's from T1 table for question p so if T2 has 7 records for Question Q then P also should have 7 records but newly generated id of T1 table of Question P.
Insert into T2 (T1_ID, Ans)
Select (T1_ID where Question=P), Ans From T2
Output
Table T1
Id Test Question
-----------------
1 Test1 Q
2 Test2 Q
3 Test3 Q
4 Test1 P
5 Test2 P
6 Test3 P
Table T2
ID T1_ID Ans
------------
1 1 A1
2 1 A2
3 2 B1
4 2 B2
5 2 B3
6 3 C1
7 3 C2
8 4 A1
9 4 A1
10 5 B1
11 5 B2
12 5 B3
13 6 C1
14 6 C2