DigitalOcean, un eccezionale servizio di Cloud Hosting, da provare! Inoltre, suggerendolo puoi guadagnare :)

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

DigitalOcean, un eccezionale servizio di Cloud Hosting, da provare! Inoltre, suggerendolo puoi guadagnare :)

Cerca su Wiki

Cerca su Google

Cerca nel Blog con Google