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 1000
眼角桃花
眼角桃花 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:37

    Try this

    Use Top

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

    Or you can use IN clause

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

提交回复
热议问题