SELECT多个SQL的SQL结果

时间:2015-12-06 17:37:13

标签: sql loops select db2 distinct

我的代码类似于下面显示的代码并且我一直收到错误 - SELECT的结果超过一行

UPDATE myDatabaseOne.myTableOne t1
SET firstFieldToCopy = (SELECT DISTINCT alternateField 
                        FROM myDatabaseTwo.myTableTwo t2
                        WHERE t1.firstFieldToCopy = t2.alternateField 
                          AND t2.Field <> t2.Field2); 

如何让它循环t1中的每个值?

1 个答案:

答案 0 :(得分:0)

It sounds like the sub query returns multiple values for (some of) the record(s) updated. You should change it so it is guaranteed only to return a single value, e.g. add TOP 1 in the select (although that does make it more or less pick a value at random)