I’m trying to select some data from a task table, but not any subtasks which a user may have created for themselves. So, I want to filter out any tasks that have a parent_taskid which is a task_id already assigned to that user.
E.g.
UserID | Parent_TaskID | TaskID
------ | ------------- | ------
435 | 149329 | 161280
435 | 149330 | 210717
435 | 149330 | 228100
435 | 156991 | 149330
169 | 161280 | 546540
169 | 456842 | 458764
So from the table above TaskIDs 210717 & 228100 would be removed from my select because their parent (149330) is a taskID already assigned to that user – making them subtasks. – but 546540 would not be removed because it is a taskID assigned to another user.
So I’m thinking something like
select Task.taskID, Task.Parent_taskID, Task.userID
from task
where Task.Parent_TaskID not in (??? select taskID from task where ???)
Any ideas?
Your
NOT INwill beanother good (and readable) solution is to use the
NOT EXISTS