I need to delete entries in a join table where rows to be deleted are selected using aggregate selection of other tables (as asked here). Unfortunetly delete statement fails and MySQL/MariaDB throws the following error:
ERROR 1093 (HY000) at line 1: You can't specify target table 'pcld' for update in FROM clause
I thought that deleting data within a table based on select clause in the same table was supported.
MariaDB version is "mysql Ver 15.1 Distrib 5.5.65-MariaDB, for Linux (x86_64)"
SQL script
DELETE pcld
FROM persons_linked_companies as pcld
WHERE pcld.id IN(
SELECT
id
FROM
persons_linked_companies pcl
WHERE
companies_id = (SELECT
c.id
FROM
companies c
INNER JOIN entities e ON e.company_id = c.id
INNER JOIN persons p ON p.entity_id = e.id
WHERE
p.id = pcl.persons_id)
)
SELECT portion of this script is courtesy of nbk, see answer here