2011-02-17 63 views
0

我有一个查询:错误查询更新的MySQL

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

你得到了什么错误? – SergeS 2011-02-17 08:07:56

+0

也许尝试给你的子查询添加一个限制1? – 2011-02-17 08:12:09

回答

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) 
0
order by a,id) 

这是一个错字?

**","**使用它应该是a.id

并添加从对方的回答下面这可能是returning more than one result,因为order by条件我认为!