Reputation: 33956
I want to copy row with ID = 1 to a new row in the same table. But two columns (UID and Date) must not be the same as the original row.
INSERT IGNORE INTO `Posts` (`A`,`B`,`UID`,`Date`) VALUES
How do I get all values from row with ID = 1 but change UID to 2 and Date to NOW()?
Upvotes: 1
Views: 61
Reputation: 53535
Try:
INSERT IGNORE INTO `Posts` (`A`,`B`,`UID`,`Date`)
select a, b, 2, now() from `Posts` where UID = 2;
See example
Upvotes: 0
Reputation: 11104
INSERT INTO `Posts` (`A`,`B`,`UID`,`Date`)
SELECT col1, col2, `your definedvalue1`,`your defined date `,
FROM this_table
WHERE 1>0(your condition);
Upvotes: 1
Reputation: 54032
TRY
INSERT INTO Posts (`A`,`B`,`UID`,`Date`)
SELECT `A`,`B`,`UID`,`Date` FROM Post
ON DUPLICATE KEY UPDATE UID =2 DATE =NOW()
Note: make index on UID and Date column
Upvotes: 0