I'm confused as to why this is not working, I've used this type of syntax several times but this one as got me pulling my hair out.
I have two tables;
tableA
regId name regStatus
1 George 1
2 Jenny 1
3 Penny 1
4 James 1
5 Preston 1
6 Jamie 0
TableB
activeRegId passiveRegID Status
1 2 1
1 3 1
1 4 0
6 1 1
What I'm trying to do is return all rows from tableA
excluding those where (tableA.regstatus = 0)
and (tableB.status = 1 for a user regid = 1)
.
I want to avoid having to use NOT IN (select ...)
.
My query so far:
select top 10
tA.regId, tA.name
from
tableA tA
left OUTER JOIN
tableB tB ON tB.activeRegId = tA.regid AND tB.passiveRegID <> 1
AND tB.status <> 1 AND tB.passiveRegID IS NULL
where
tA.regStatus = 1
and tA.regid <> 1
What I'm expecting back should be as follows however, I'm getting all the users in tableA
except for Jamie.
regId name
4 James
5 Preston