mysql - 'a1.location' 中的未知列 'where clause'

标签 mysql

我正在尝试执行此查询

UPDATE airport AS a1, 
(SELECT location_ar 
FROM airport as a3 
WHERE a3.location = a1.location AND a3.location_ar != NULL LIMIT 1) as a2 
SET a1.location_ar = a2.location_ar WHERE a1.location = NULL;

但是我收到“'where 子句'中的未知列'a1.location'”,

编辑:新查询是:

UPDATE airport AS a1, (SELECT location_ar FROM airport WHERE location = a1.location AND a3.location_ar != NULL LIMIT 1) as a2 SET a1.location_ar = a2.location_ar WHERE a1.location = NULL;

请帮忙

最佳答案

更好的方法是使用 join

update airport a1
join airport a2 on a1.location = a2.location and a2.location_ar is not NULL
set a1.location_ar = a2.location_ar
where a1.location is NULL;

关于mysql - 'a1.location' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29609721/

相关文章:

php - wordpress 无法访问管理部分和网站,因为主题不存在

sql - MySQL慢查询

html - 没有这样的文件或目录 : var/www/html in ec2 instance

php - 测试的数据库结构

mysql - 存储过程一遍又一遍地插入相同的值

mysql - Magento 将所有订单号在两个日期之间隔夜发货

php - 使用 PHP 实时从 MySQL 抓取数据?

mysql - 选择分组值和值的总和

mysql - 在列中插入 ID,值以逗号分隔

mysql - Grails 立即提交事务中的对象