Mysql
 sql >> Database >  >> RDS >> Mysql

Errore (1093):non è possibile aggiornare la tabella di destinazione per l'aggiornamento nella clausola FROM

avvolgerlo in una sottoquery (creando così una tabella temporanea )

UPDATE  o_daily_lcsgeneration_copy
SET     o_daily_lcsgeneration_copy.Billing_cycle = 
(
    SELECT Billing_cycle
    FROM
    (
        SELECT  s_billing_cycle.Billing_cycle
        FROM    s_billing_cycle
                INNER JOIN o_daily_lcsgeneration_copy
                    ON o_daily_lcsgeneration_copy.Location = s_billing_cycle.Location
        WHERE   o_daily_lcsgeneration_copy.DATE BETWEEN s_billing_cycle.From_Date
                AND s_billing_cycle.To_Date
    ) s
)

o JOIN le tabelle

UPDATE  o_daily_lcsgeneration_copy a
        INNER JOIN s_billing_cycle b
            ON a.Location = b.Location
SET     a.Billing_cycle = b.Billing_cycle
WHERE   a.DATE BETWEEN b.From_Date AND b.To_Date