You could use EXISTS
and a correlated subquery to filter on rows whose UserId
has at least one audit event of id 14
:
UPDATE h
SET IsActivated = 1
FROM [dbo].HRUser h
WHERE EXISTS (
SELECT 1 FROM
FROM dbo.[UserAudit] a
WHERE a.UserId = h.UserId AND a.AuditTypeId = 14
)
Note that there is no point reopening the target table in the subquery; you just need to correlate it with the outer query.
CLICK HERE to find out more related problems solutions.