Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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
为什么要额外添加一层SELECT resolve Mysql错误代码:1235_Mysql_Mysql Workbench - Fatal编程技术网

为什么要额外添加一层SELECT resolve Mysql错误代码:1235

为什么要额外添加一层SELECT resolve Mysql错误代码:1235,mysql,mysql-workbench,Mysql,Mysql Workbench,在我前面的一个问题中,我询问了解决mysql 1235错误的解决方案: 错误代码:1235。这个版本的MySQL还不支持“限制”& 在/ALL/ANY/SOME子查询中' 以下将抛出1235: DELETE FROM job_detail_history where id not in (select id from job_detail_history order by start_time desc limit 2); 为此,我得到了@Zaynul Abadin Tuhi

在我前面的一个问题中,我询问了解决mysql 1235错误的解决方案:

错误代码:1235。这个版本的MySQL还不支持“限制”& 在/ALL/ANY/SOME子查询中'

以下将抛出1235

 DELETE
    FROM job_detail_history
    where id not in (select id from job_detail_history order by start_time desc limit 2);
为此,我得到了@Zaynul Abadin Tuhin给出的解决方案 如下所示,它也适用于我。他只是在我的子查询上添加了一个选择层。根据他的说法,这是一些mysql专家的建议。
解决上述问题的方法

 DELETE
    FROM job_detail_history
    where id not in (select * from
        (select id from job_detail_history order by start_time desc limit 2) as t1 );

我尝试对DB表进行分析,发现当我使用
问题::如上所述,删除操作不起作用

select id from job_detail_history order by start_time desc limit 2;
它给我的回报是这样的:

最后一个
null
用于工作台建议的新行:

当我添加一层额外的select时:
添加额外的子查询层:这将适用于我的删除

(select id from (select id from job_detail_history order by start_time desc limit 2)  as t1);
它返回如下内容:

所以,我想了解的是
具有一个额外层的子查询如何解决1235错误?


任何人都可以详细说明它。

a和a之间有一个重要的区别

派生表替换表(在您也可以使用“普通”表名的情况下使用),特别是在
from
join
中,它需要别名(或“表名”,因为它与任何其他表一样使用)。不能在不在()中的位置写入
;这不是派生表,而是子查询

通常,此问题(以及使用另一层的解决方案)发生在:

不能在子查询中从表中删除并从同一表中选择

但不禁止使用此表的派生表。MySQL根本无法处理(或不想处理)这种内部工作方式(以及根据其规则)的依赖性

对于
限制
,有一个类似的

MySQL不支持对某些子查询运算符进行子查询限制

错误1235(42000):此版本的MySQL尚不支持 '在/ALL/ANY/SOME子查询中限制(&I)'

至于它对MySQL产生影响的原因:派生表独立存在,不能依赖外部查询。它可以像普通表一样在内部使用。(例如,MySQL可以在执行计划的第一步简单地创建这个表,并在那里执行所有后续步骤。)另一方面,子查询可以依赖于外部表(使其成为从属子查询)

具体来说,

 where id not in (select id from job_detail_history);

 where not exists (select id from job_detail_history sub where sub.id = outer.id);
 where not exists (select id from job_detail_history sub 
                   where sub.id = outer.id limit 2);
虽然您无法对
限制执行此操作

 where id not in (select id from job_detail_history limit 2);
不一样

 where not exists (select id from job_detail_history sub where sub.id = outer.id);
 where not exists (select id from job_detail_history sub 
                   where sub.id = outer.id limit 2);

MySQL根本无法处理这个问题,因为它已经习惯于进行这种转换。但它迟早会允许这样做的。要使其用于删除,您仍然需要使用子查询。

因为mysql不允许这样做。通过使用join,您可以it@AnkitAgrawal,但在任何地方都没有提到添加一个额外的select层将解决您的问题。我不清楚这些查询中的哪一个真正起作用。“你们可能想花点时间突出这一点。”TimBiegeleisen,我更新了问题。希望这将是容易让你理解。我现在删除的答案是不远,我想。解决方法显然与具体化
限制
子查询有关,然后针对该子查询运行
WHERE IN
。至于这到底是为什么,我们必须深入研究执行计划和类似的事情,看看MySQL在每一步都在做什么。很好。感谢您提供mysql文档,这将澄清这个问题。