kalls kalls - 2 months ago 4x
SQL Question

Copy rows from the same table and update the ID column

I have the following table

alt text

I have inserted Product B to it and it gives me an ID of 15

Then I have the definition table which is as follows.

alt text

I want to select the ProductDefinition rows where ProdID = 14 and replicate the same and insert it for ProdID = 15 like the following

alt text

How to achieve this using SQL code?

INSERT INTO ProuctDefinition (ProdID, Definition, Desc)
  xxx, Definition, Desc
  ProdID = yyy

The xxx is your new ProdID and the yyy is your old one. This also assumes that DefID is automagically populated on INSERT.