I worked up the solution below. However it does not match your desired output since there are no tasks owned by user2, user3 or user4. For example, why are you showing user2 as the owner of ID=1? The input data does not have that.--INPUTdeclare @input table ([OWNER] varchar(10), ID int, TASK_ID int, TASK_ASSIGNEE varchar(10))insert into @input ([OWNER], ID, TASK_ID, TASK_ASSIGNEE) values('user1', 1,1,'user2'),('user1', 1,2,'user3'),('user1', 1,3,'user4')--PRIVILEGE tabledeclare @privilege table (USER_DETAIL varchar(10), PRIVILEGE_ID int)insert into @privilege (USER_DETAIL, PRIVILEGE_ID) values('user1', 10),('user1', 11),('user1', 12),('user2', 8 ),('user3', 5 ),('user4', 6 )select distinct [OWNER], ID, TASK_ID, TASK_ASSIGNEEfrom @input ijoin @privilege p on i.task_assignee = p.user_detailwhere p.PRIVILEGE_ID not in ( select PRIVILEGE_ID from @privilege where USER_DETAIL = 'user1')