Page 1 of 1

Replicate Record in MySQL

PostPosted: Thu Apr 11, 2013 12:26 am
by douglas
We can duplicate records in our MySQL table using SELECT COUNT(*) FROM YOUR_TABLE;

INSERT INTO YOUR_TABLE
SELECT *
FROM YOUR_TABLE
WHERE COUNT =(SELECT COUNT(*)
FROM YOUR_TABLE);

Duplicate record is only possible if your table has no primary key as primary key will not allow duplicates otherwise its ok to duplicate record.

Re: Replicate Record in MySQL

PostPosted: Thu Apr 11, 2013 2:11 am
by silvester
This type of SQL statement is helpful when we are fetching entire row from one table and inserting to another for ex:-in e-commerce projects. Need to make sure that the fields in both table are same.