Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQL错误1248 I';我卡住了_Mysql_Sql_Derived Table - Fatal编程技术网

MYSQL错误1248 I';我卡住了

MYSQL错误1248 I';我卡住了,mysql,sql,derived-table,Mysql,Sql,Derived Table,好的,我对派生表还不熟悉。当我运行这个查询时,它会给我一个MYSQL错误1248。有人知道这方面的工作吗?这可能是我做过的最复杂的查询,我只是想让它工作起来。谢谢大家! delete from table_1 where thing_id in ( select tid from( select thing_id as tid FROM table_1 inner join table_2

好的,我对派生表还不熟悉。当我运行这个查询时,它会给我一个MYSQL错误1248。有人知道这方面的工作吗?这可能是我做过的最复杂的查询,我只是想让它工作起来。谢谢大家!

delete from table_1
    where thing_id in (
        select tid from(
            select thing_id as tid
            FROM table_1
            inner join table_2
            on table_1.thing_id = table_2.thing_id
            where stuff = 'stuff'
            )
        )
您忘记了表别名

您忘记了表别名


MySQL通常不允许您在语句的其余部分引用正在删除(或更新)的表。您可以使用嵌套的子查询来解决这个问题(就像您试图做的那样)。但是,我认为最好使用显式的
join
s进行更新:

delete t1
    from table_1 t1 join
         (select t1.thing_id as tid
          from table_1 t1 inner join
               table_2 t2 
               on t1.thing_id = t2.thing_id
          where stuff = 'stuff'
        ) tt
        on t1.thing_id = tt.tid;
这就是说,我认为这相当于在
表2上执行
连接

delete t1
    from table_1 t1 join
         table_2 t2 
         on t1.thing_id = t2.thing_id;
   where stuff = 'stuff';

后一种方法也应该有更好的性能。

MySQL通常不允许您在语句的其余部分引用正在删除(或更新)的表。您可以使用嵌套的子查询来解决这个问题(就像您试图做的那样)。但是,我认为最好使用显式的
join
s进行更新:

delete t1
    from table_1 t1 join
         (select t1.thing_id as tid
          from table_1 t1 inner join
               table_2 t2 
               on t1.thing_id = t2.thing_id
          where stuff = 'stuff'
        ) tt
        on t1.thing_id = tt.tid;
这就是说,我认为这相当于在
表2上执行
连接

delete t1
    from table_1 t1 join
         table_2 t2 
         on t1.thing_id = t2.thing_id;
   where stuff = 'stuff';

后一种方法也应该有更好的性能。

?不,淘气?是;-)第一部分与问题无关。也就是说,第二部分看起来很到位@草莓。我想说,在数据库中使用不受支持的语法与问题密切相关。它可能不需要专门处理语法错误,但OP将修复该错误,然后再得到另一个错误。如果这是原因的话,我觉得这是恶意的,因为第一个解决方案是正确地重新编写查询(尽管特定代码中可能存在语法错误)。“MySQL不允许您引用正在删除的表”。这句话是真的。这与这个问题无关,因此juergen d提出了解决方案。我怀疑我们对恶意的本质有不同的看法。您是否缺少
table_1
表既被删除又在子查询中?如果您对问题的理解是正确的,那么Juergen的解决方案将返回错误消息,对吗?但它不是,恶意的?不,淘气?是;-)第一部分与问题无关。也就是说,第二部分看起来很到位@草莓。我想说,在数据库中使用不受支持的语法与问题密切相关。它可能不需要专门处理语法错误,但OP将修复该错误,然后再得到另一个错误。如果这是原因的话,我觉得这是恶意的,因为第一个解决方案是正确地重新编写查询(尽管特定代码中可能存在语法错误)。“MySQL不允许您引用正在删除的表”。这句话是真的。这与这个问题无关,因此juergen d提出了解决方案。我怀疑我们对恶意的本质有不同的看法。您是否缺少
table_1
表既被删除又在子查询中?如果您对问题的理解是正确的,那么Juergen的解决方案将返回错误消息,对吗?但事实并非如此,