Skip to content
Advertisement

Copy rows in MySQL table multiple times and adding additional column

I have created MySQL table in database. Table name is products and the columns are( prodict_id(pk) product_name and pack_size) as shown in the figure below.

What I want to do is , copy all the rows in the table and add additional information in additional column called (buyer_name) so each product is associated with a specific buyer which makes it unique

mysqltable Is there a way I can achieve this using query? Where I can give a list of buyers and it attaches it to all rows in table?

p.s I have almost 700 rows in my table and I have 12 buyers, so if I do it manually, it will consume too much time

Advertisement

Answer

As per your comment your buyer details are in a table and you want to map each product with each of the buyer then you can write your insert query like below:

insert into newtable
select t1.*, t2.buyername from products t1 join buyers t2

DEMO

You can use where clause also to filter some results from either of the table.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement