简体   繁体   English

子查询返回1行以上

[英]Subquery returns more than 1 row

I have this query: 我有这个查询:

UPDATE student_info 
    set grade = (SELECT tempTable.grade 
                     FROM tempTable
                     WHERE student_info.s_id = (SELECT s_id FROM tempTable))

I've also tried the suggested solution here: http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html 我也在这里尝试了建议的解决方案: http : //dev.mysql.com/doc/refman/5.0/en/subquery-errors.html

I guess you want: 我想你要:

UPDATE student_info 
  JOIN tempTable
    ON tempTable.s_id = student_info.s_id 
SET student_info.grade = tempTable.grade 

Your subquery is returning more than one row, possibly because the JOIN is incorrect. 您的子查询返回了多个行,可能是因为JOIN错误。 Try: 尝试:

UPDATE student_info 
    SET grade = (SELECT grade 
         FROM tempTable
         WHERE s_id = student_info.s_id)

This of course assumes that tempTable only contains one record per s_id . 当然,这假定tempTable每个s_id仅包含一个记录。 If there are more that one then you need to take the TOP 1 ordered by some attribute (latest? highest?) 如果有多个,那么您需要按某种属性(最新?最高?)排序的TOP 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM