php - 奇怪的 : can't specify target table for update in FROM clause

标签 php mysql sql database sql-update

我不明白为什么我的查询在 phpMyAdmin 中运行良好,而在我的 php 脚本中它给我消息:无法在 FROM 子句中指定要更新的目标表!!!

update tableA set 
Field1 = round(round((select (select br.FieldA from tableB br where tableA.id=br.id and tableA.id2=br.id2) as x),4) - round(tableA.FieldA,4),4)

最佳答案

没错。您不能在嵌套查询中选择您现在正在更新的同一个表。

更好的解决方案是在您的更新中使用连接。 http://dev.mysql.com/doc/refman/5.5/en/update.html

关于php - 奇怪的 : can't specify target table for update in FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4843217/

相关文章:

php - Laravel 4.2 从选择中插入

php - 在进行 mysql 查询时将 php 变量设置为无穷大

mysql - 在 MySQL 中将多行作为单行获取

php - Zend_Db_选择 : Working with JOIN's

mysql - 我怎样才能得到那些具有所有状态的ID?

php - 为什么在yii框架中使用Chtml

php - 无法查看laravel中的数据集合

database - MySQL内连接问题或其他同等解决方案

android - 使用PHP将图像插入android中的mysql数据库

sql - 如何通过 PostgreSQL 更新特定列的特定行以反射(reflect)另一个表中的值?