I’m attempting to perform a duplicate clean-up query in MySQL, using a contacts table, and an accounts_contacts joining table. I have the query working as a SELECT query, but when I try to make it an UPDATE, I’m getting a very unspecific error:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FROM sugarDB.contacts INNER JOIN ( SELECT dupIDs.id FROM ( SELECT ct’ at line 3
Here is the Query:
UPDATE ctUpdate
SET ctUpdate.deleted = 1
FROM sugarDB.contacts AS ctUpdate
INNER JOIN (
SELECT dupIDs.id
FROM (
SELECT ctIDs.id
FROM sugarDB.contacts AS ctIDs
INNER JOIN (
SELECT ctSource.first_name,
ctSource.last_name
FROM sugarDB.contacts AS ctSource
GROUP BY ctSource.first_name,
ctSource.last_name
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
)
AS ctSource
ON ctIDs.first_name = ctSource.first_name
AND ctIDs.last_name = ctSource.last_name
)
AS dupIDs
LEFT JOIN sugarDB.accounts_contacts AS a2cIDs
ON dupIDs.id = a2cIDs.contact_id
WHERE a2cIDs.id IS NULL
)
AS dupIDs
ON ctUpdate .id = dupIDs.id
;
I have poured over it for a few days now, and I can’t find the error. Any help is greatly appreciated!
There is no
FROMclause inUPDATEstatements in MySql.Instead, your joins should be part of your
UPDATEclause: