Update join throws error: Subquery returned more than 1 value

I am trying to do an update like this:

UPDATE a
SET a.PackageID = p.ID
FROM gym.Account a
JOIN Packages p
ON a.MembershipTypeID = p.MembershipTypeID
and a.SiteID = p.SiteID
and a.SiteID = 1

      

I am getting the error

Subquery returned more than 1 value

I don't see how this error message can be accurate because when I ask:

select 
    ID, SiteID, PackageName, MembershipTypeID
from 
    Packages
where 
    siteid = 1
order by 
    MembershipTypeID, PackageName

      

... the values ​​are MembershipTypeID

unique - no duplicates!

So I looked at the stack question here and tried this:

UPDATE gym.Account  
SET PackageID = (SELECT top 1 ID
                 FROM Packages
                 WHERE gym.Account.MembershipTypeID = MembershipTypeID)

      

But I still get the same error message even though I'm doing TOP 1. How can I fix this?

+3


source to share


1 answer


Check if there is a trigger on the table. This could be the reason for your error.



:)

+4


source







All Articles