MySQL数据库错误:子查询返回超过1行

时间:2014-02-14 10:17:30

标签: mysql

请看下面的查询,我试图从另一个似乎有重复的表更新一个表。

运行此声明的正确方法是什么?

UPDATE doc SET idx2 = (SELECT imp.idx2 FROM imp WHERE imp.idx1 = doc.idx1),
idx3 = (SELECT imp.idx3 FROM imp WHERE imp.idx1 = doc.idx1)
WHERE doc.boxid IN (SELECT box.id FROM box WHERE box.profid = 41 
AND box.boxname = '1153-BATCH0011') AND doc.idx2 = ''

1 个答案:

答案 0 :(得分:0)

如果您确定子查询返回的重复值相同,则可以使用LIMIT 1,这样子查询只返回1个结果。

UPDATE doc SET idx2 = (SELECT imp.idx2 FROM imp WHERE imp.idx1 = doc.idx1 LIMIT 1),
idx3 = (SELECT imp.idx3 FROM imp WHERE imp.idx1 = doc.idx1 LIMIT 1)
WHERE doc.boxid IN (SELECT box.id FROM box WHERE box.profid = 41 
AND box.boxname = '1153-BATCH0011') AND doc.idx2 = ''