Mysql
 SQL >> Database >  >> RDS >> Mysql

Aggirare “Can’t specify target table for update in FROM clause”

MySQL non consente di modificare una tabella mentre la selezioni nella stessa query tramite sottoquery. Una soluzione è annidare ulteriormente la sottoquery, forzando l’uso di una tabella temporanea:

DELETE FROM wp_mail_queue
WHERE message_id = (
  SELECT *
  FROM (
    SELECT message_id
    FROM wp_mail_queue
    ORDER BY id
    LIMIT 0, 1
  ) queue_table
)
ORDER BY wp_mail_queue.id
LIMIT 100;