1
copy row from one table to different in same db
CGuild1.com > Tips & Tricks > copy row from one table to different in same db

Copy row from one table to different in same db

Here is how to copy a row from one table in a mySQL database into a different table in the same db.

INSERT INTO secondTableName
    SELECT d.*, CURRENT_DATE()
    FROM firstTableName d
WHERE fieldName = '5';


Be VERY CAREFUL doing this. It does work, but it assumes the order of columns in the two tables is identical; it does not match by column name, and does try to coerce values to fit, which can cause unexpected results. Now, if your development structure assures the column orders are identical bar the last column, it's a convenient and straightforward way to do it, but the caveat is important. – T.J. Crowder


I found this over here at Stackoverflow.
©2024 CGuild1.com