我对为什么这不起作用感到困惑,我已经多次使用过这种类型的语法,但这种语法让我把头发拉了出来。
我有两张桌子;
表A
regId name regStatus
1 George 1
2 Jenny 1
3 Penny 1
4 James 1
5 Preston 1
6 Jamie 0
表B
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