2011-02-17 59 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條件我認爲!