错误1109(42S02):MULTI DELETE中的未知表

时间:2019-06-20 18:26:31

标签: mysql sql

我将临时表t与这些查询一起使用,以便从comment表中删除重复的行:

CREATE TABLE t (
        id INT NOT NULL,
        hash BINARY(20),
    PRIMARY KEY(id),
    INDEX(hash) ) ENGINE=InnoDB;

INSERT INTO t (id, hash)
    SELECT id, UNHEX(SHA1(body))
        FROM `comment`;

DELETE FROM `comment`
       USING t AS t1,
             t AS t2
       WHERE t1.id = comment.id
         AND t2.hash = t1.hash AND t2.id < t1.id;

但是在删除阶段,出现此错误:

ERROR 1109 (42S02): Unknown table 'comment' in MULTI DELETE 

我该如何解决?

1 个答案:

答案 0 :(得分:2)

MySQL在USING中不支持DELETE。我想你想要

DELETE c
    FROM `comment` c JOIN
         t t1
         ON t1.id = c.id JOIN
         t t2
         ON t2.hash = t1.hash AND t2.id < t1.id;

我怀疑有更简单的方法可以表达这种逻辑。也许您应该问另一个问题,包括样本数据,期望的结果以及对所实现逻辑的解释。