[SOLVED] mysqli UPDATE ON DUPLICATE KEY using a condition
Posted: Sun Jun 19, 2016 11:56 am
I am importing data from a delimited file to a temp table and then using the temp table to update another table. This is working just fine.
My problem is that I now need to UPDATE rows only if "date" in the table is greater than the current date. Here's a simplified version of the query I was using until I discovered that mysqli does not support WHERE in the UPDATE clause.
Additional research shows that I can add a conditional IF to "table.date = temp_table.date", but that condition only applies to that one field. I suppose I could add the same condition to every field, but I'm wondering if there's a better way to achieve my goal.
Thanks in advance.
My problem is that I now need to UPDATE rows only if "date" in the table is greater than the current date. Here's a simplified version of the query I was using until I discovered that mysqli does not support WHERE in the UPDATE clause.
Code: Select all
INSERT INTO table SELECT * FROM temp_table ON DUPLICATE KEY UPDATE
table.first = temp_table.first,
table.last = temp_table.last,
table.date = temp_table.date
WHERE table.date > CURDATE()Thanks in advance.