SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows (chars) or when the subquery is used as an expression

后端 未结 3 998
眼角桃花
眼角桃花 2021-02-19 20:14

I am trying to update some fields based on their occurence. If they only occur one time, I am updating some status field.

My current code is as follows:

         


        
3条回答
  •  逝去的感伤
    2021-02-19 20:33

    Use IN keyword instead of equals operator like so:

    UPDATE table1
    SET statusField = 1
    WHERE someID IN (
               SELECT someID
               FROM table1
               GROUP BY someID HAVING COUNT(*) = 1
               )
    

    Using = requires that exactly 1 result is returned by the subquery. IN keyword works on a list.

提交回复
热议问题