なぜこれが機能しないのか混乱しています。このタイプの構文を数回使用しましたが、これは髪の毛を抜くようになりました。
2つのテーブルがあります。
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
私がやろうとしているのはtableA
、where(tableA.regstatus = 0)
と。を除いたすべての行を返すことです(tableB.status = 1 for a user regid = 1)
。
使用する必要はありませんNOT IN (select ...)
。
これまでの私の質問:
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
私が期待しているのは次のとおりですが、tableA
Jamieを除くすべてのユーザーを受け入れています。
regId name
4 James
5 Preston