We have a table as follows
- an employee can belong to multiple departments. a department can contain many employees
EmployeeId Dept
John123 Sales
John123 Marketing
John123 Ads
Kevin32 Promotions
Kevin32 Marketing
In case if John123 is removed from Ads then one of our component gets a message with a list {Sales, Marketing} and EmployeeId as John123. We don't know the fact that "Ads" is removed.
Ultimately, we need to remove the row "John123" and "Ads"
One simple way is to construct a query like
Delete from table where EmployeeId = 'John123' and Dept Not In {Sales, Marketing} but there can be many huge departments in case of multi national company.
I am just looking for efficient way of performing this. Does Merge statement helps by any chance?
Thanks
Sahasra