I have a project where on a weekly basis I import several large datasets that contain incorrect data, such as duplicate employee IDs where they should not be duplicates. In an effort to flag the duplicates, I try the following code:
ALTER TABLE AccountDuplicates
ADD UNIQUE INDEX EmployeeID (EmployeeID);
INSERT INTO AccountDuplicates
SELECT
EmployeeID,
FirstName,
LastName
FROM AccountsWork
ON DUPLICATE KEY UPDATE
EmployeeID = CONCAT(VALUES(EmployeeID), '*');
The INSERT statement gives me errors, and I do not see what I am doing wrong:
[42000][1064] You have an error in your SQL syntax; check the manual that correspondsto your MySQL server version for the right syntax to use near 'FROM EAD_UserAccountsWork
ON DUPLICATE KEY UPDATE EmployeeID = CONCAT(VALUES(E' at line 36
In case it is relevant, I am running MySQL 5.7.12 on OS X 10.11.4, INNODB engine and mysql_mode = ''. My intent here is to identify the duplicate IDs so I can forward them to the appropriate DBAs for correction.
Update: I have set the database defaults as follows:
[client]
default-character-set = utf8mb4
[mysqld]
sql_mode=''
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4