我有一个问题:
update customers_training_malaysia
set
period_id = (select b.id
from customers_training_malaysia a,training_schedules_malaysia b
where a.sch_code=b.sch_code order by a,id)
where
sch_code = (select b.sch_code
from customers_training_malaysia a,training_schedules_malaysia b
where a.sch_code = b.sch_code order by a.id)
我尝试运行以下查询更新,但我只得到错误
用作表达式
的子查询返回的多行我该怎么做才能纠正sql查询?
答案 0 :(得分:1)
您必须在
中获取所有子查询set [field_name] = ([subquery])
并检查此查询仅返回结果中的一条记录。 这就是错误的原因 - 子查询中有多个结果
试试这个:
update customers_training_malaysia
set
period_id = b.id
where
sch_code = (select b.sch_code
from customers_training_malaysia a,training_schedules_malaysia b
where a.sch_code = b.sch_code order by a.id)
答案 1 :(得分:0)
order by a,id)
这是一个错字吗?
**","**
使用它应该是a.id
并从其他答案添加下面可能是returning more than one result
,因为我假设order by
条件!