Code: Select all
INSERT INTO `table`
('col1','col2','col3') VALUES
('val1','val2','val3'),
('val4','val5','val6'),
('val7','val8','val9')
ON DUPLICATE KEY UPDATE
`col1`=VALUES(`col1`),
`col2`=VALUES(`col2`)Moderator: General Moderators
Code: Select all
INSERT INTO `table`
('col1','col2','col3') VALUES
('val1','val2','val3'),
('val4','val5','val6'),
('val7','val8','val9')
ON DUPLICATE KEY UPDATE
`col1`=VALUES(`col1`),
`col2`=VALUES(`col2`)count_before - count_after = inserted rowsonion2k wrote:I can compare the cardinality of the table before and after to get the number of inserts, but I'd also like to figure out the number of rows that were updated (if any).
If you use INSERT ... ON DUPLICATE KEY UPDATE to insert a row, mysql_affected_rows() returns 1 if the row is inserted as a new row and 2 if an existing row is updated.