happenask happenask - 5 months ago 9
MySQL Question

MYSQL ONDUPLICATE KEY UPDATE ISSUE

I am trying to use 'ON DUPLICATE KEY UPDATE' statement to update column when duplicate primary key are already in table.
but even if table has duplicated primary key, it does not update column.

below is 'ON DUPLICATE KEY UPDATE' statement.
is there somthing wrong?

ON DUPLICATE KEY UPDATE authenticated = authenticated
and notAuthenticated = notAuthenticated
and stoped = stoped
and deleted = deleted
and updatedDate = now()


;

Answer

Don't use AND, but use commas:

 ON DUPLICATE KEY UPDATE
              authenticated = VALUES(authenticated),
              notAuthenticated = VALUES(notAuthenticated),
              stoped = VALUES(stoped),
              deleted = VALUES(deleted),
              updatedDate = now()