I have one temporary table that contains userID and taskID. It is called CompletedTasks.
I have a second table that contains userID and taskID. It is called PlannedTasks.
I need to get a list of all taskIDs that were completed, but not planned.
So, I need to somehow weed out from completed tasks, all rows where both:
PlannedTasks.userID != CompletedTasks.userID
AND
PlannedTasks.taskID != CompletedTasks.taskID
You can use this (more compact syntax):
or the
NOT EXISTSversion (which although more complex, should be more efficient with proper indexes):and of course the
LEFT JOIN / IS NULLversion that @jmacinnes has in his answer.