468x60

lunedì 27 gennaio 2014

Mysql error 1093 - Can't specify target table for update in FROM clause

Queries of the following type can not be run on MySQL, because in a DELETE query you can not specify the same table both on FROM and on WHERE:
DELETE FROM story_category
WHERE category_id NOT IN (
        SELECT DISTINCT category.id AS cid FROM category 
        INNER JOIN story_category ON category_id=category.id
)
We must therefore modify the query as follows:
DELETE FROM story_category
WHERE category_id NOT IN (
    SELECT cid FROM (
        SELECT DISTINCT category.id AS cid FROM category 
        INNER JOIN story_category ON category_id=category.id
    ) AS c
)

Nessun commento:

Posta un commento

468x60

Cerca su Google

Cerca nel Blog con Google