I have a CSV import into a temp_import_table in which I’m validating the imported data before commiting to the database (mysql 5.0.88).
I’m trying to search the records in the validation table for duplicate entries, but I can’t get it to work like this:
<cfquery datasource="#session.datasource#">
UPDATE import_pricat_csv
SET err = "ja", errtxt = "duplicate EAN"
WHERE iln = <cfqueryparam value="#Session.logId#" cfsqltype="cf_sql_varchar" maxlength="16">
AND ean IN (
SELECT ean
FROM import_pricat_csv
GROUP BY ean
HAVING COUNT(ean) > 1
)
</cfquery>
This throws an error:
You can't specify target table 'import_pricat_csv' for update in FROM clause
Question:
Is this not possible? Is there a better way than to loop once to get duplicates and a second time to set dup-records to err="yes"
Thanks!
You can use the multiple-table
UPDATEsyntax to join with the materialised group results: