发布于 2015-08-27 14:27:49 | 182 次阅读 | 评论: 1 | 来源: PHPERZ

这里有新鲜出炉的Mysql教程,程序狗速度看过来!

Mysql关系型数据库管理系统

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。


按照MYSQL5.0文档的解释:我们不能在修改表A的同时在其子查询中使用到表A,但是可以通过在子查询中在嵌套一层针对表A的子查询,因为最里层的子查询产生的结果存在临时表中,与表A没有关系。

解决方法:把类似于 UPDATE t ... WHERE col = (SELECT ... FROM t ...); 改写成UPDATE t ... WHERE col = (SELECT (SELECT ... FROM t...) AS _t ...);即可。

文档原文:In general, you cannot modify a table and select from the same table in a subquery. For example, this limitation applies to statements of the following forms:

DELETE FROM t WHERE ... (SELECT ... FROM t ...);UPDATE t ... WHERE col = (SELECT ... FROM t ...);{INSERT|REPLACE} INTO t (SELECT ... FROM t ...);

Exception: The preceding prohibition does not apply if you are using a subquery for the modified table in the

FROM

clause. Example:

UPDATE t ... WHERE col = (SELECT (SELECT ... FROM t...) AS _t ...);

Here the prohibition does not apply because a subquery in the

FROM

clause is materialized as a temporary table, so the relevant rows in

t

have already been selected by the time the update to

t



最新网友评论  共有(1)条评论 发布评论 返回顶部
kyee 发布于2016-02-14 18:50:43
thx
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务