insert - inserting another row in mysql database with values similar to previous row -
i have table like,
batchid volume1 volume2 volume3 1 3.0 4.0 5.0 1 2.0 1.0 2.0 2 1.0 2.0 4.0 2 1.0 1.0 1.0 2 1.0 1.0 1.0 i trying add batchid 3 same volume1, volume2 , volume3 values such looks (same records batchid 2)
1 3.0 4.0 5.0 1 2.0 1.0 2.0 2 1.0 2.0 4.0 2 1.0 1.0 1.0 2 1.0 1.0 1.0 3 1.0 2.0 4.0 3 1.0 1.0 1.0 3 1.0 1.0 1.0 i wrote following query
insert table1 (batchid,volume1,volume2,volume3) values (`3`,select volume1,volume2,volume3 table1 batchid = '2') gives error.
p.s know above not database design. on simplified version of actual design.
you can use insert ... select:
insert table1 (batchid, volume1, volume2, volume3) select 3, volume1, volume2, volume3 table1 batchid = 2
Comments
Post a Comment