Categories
Development

Update grouped rows with ID of newly inserted grouping row

I want to group several rows of table A and insert a new row into table B for each bunch of grouped rows.
Next to that I want to update the rows of table A with the ID of the newly inserted row.

Inserting the lines into the table with ‘grouplines’ is like:

INSERT INTO B(...,...,...)
SELECT col1, col2 FROM A
GROUP BY col1,col2 

This will produce a list of IDs in table B. I want to update the rows of table A with the ID of the corresponding group-row of table B.

Is there a possibilty to do this?

Some sample data:

enter image description here

After grouping table B looks like:

enter image description here

And then table A should look like:

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *