Aar Clay
Aar Clay

Reputation: 9

How can i duplicate a bunch of records in mySQL

How can I duplicate a bunch of records in mySQL?

I have records like this:

ID - name - year
-----------------
1 jasmine - 1999
2 peter   - 1999
3 fleur   - 1999

How can I duplicate all the names with WHERE year='1999' to a new row with a new year?

ID - name - year
-----------------
1 jasmine - 1999
2 peter   - 1999
3 fleur   - 1999
4 jasmine - 2000
5 peter   - 2000
6 fleur   - 2000

Any ideas?

Upvotes: 0

Views: 90

Answers (2)

Pritom
Pritom

Reputation: 1333

Try with this pls. In place of 2000 you can use as you wish.

INSERT INTO duplicate_entry (name, year) 
SELECT name, '2000' FROM duplicate_entry where year='1999'

Best of luck.

Upvotes: 0

eggyal
eggyal

Reputation: 125835

INSERT INTO mytable (name, year)
SELECT (name, 2000) FROM mytable WHERE year = 1999;

Upvotes: 4

Related Questions