PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] Copy rows in MySQL table multiple times and adding additional column

 March 05, 2022     database, datatables, mysql, php, phpmyadmin     No comments   

Issue

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


Solution

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.



Answered By - Akhilesh Mishra
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing