我有这个问题:
UPDATE student_info
set grade = (SELECT tempTable.grade
FROM tempTable
WHERE student_info.s_id = (SELECT s_id FROM tempTable))
我也在这里尝试了建议的解决方案: http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html
答案 0 :(得分:7)
我想你想要:
UPDATE student_info
JOIN tempTable
ON tempTable.s_id = student_info.s_id
SET student_info.grade = tempTable.grade
答案 1 :(得分:2)
您的子查询返回多行,可能是因为JOIN不正确。尝试:
UPDATE student_info
SET grade = (SELECT grade
FROM tempTable
WHERE s_id = student_info.s_id)
这当然假设tempTable
每s_id
只包含一条记录。如果还有更多那个,那么您需要按某个属性排序TOP 1
(最新?最高?)