Skip to content
Advertisement

UPDATE based on multiple overlapping conditions

I have a query which essentially transfers a job from one worker to another.

The query works fine, but I need to add one additional check:

  • ensure the current job owner (in jobs) is the worker matching @owner and @teamId.

This is essentially the condition that I need to add:

To the query below:

The problem is that if I add that additional check, it breaks the update since I am already filtering the workers table by the statement workers.id = @newOwnerId which is necessary to SET the new owner in jobs table. I think I might need a double join onto that table, but I’m not sure.

Advertisement

Answer

Doesn’t this work?

This appears to be what you are asking for.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement