I have one table that has fields like
ID ProductID CategoryID and lot of columns......
1 1 1
2 1 2
3 2 1
4 2 2
5 2 3
I want to insert all the records in this table to two separate tables that have a structure like
ID ProductID (Skip CategoryID column)....
1 1
2 2
And
ID ProductID CategoryID
1 1 1
2 1 1
3 2 2
4 2 2
5 2 2
I can easily do this using code but i want to use pure SQL.
Normally i can insert it like
Insert into Table1 select * from Table2
But in this case after for every row there are multiple insert.
Any idea in this regard is appreciable.
If I understand you correctly, your issue is that when you select from the first table into the second table you are getting multiple rows for each product. To get round this you can do something like :
and then to inset into the third table would just require: