私のテーブルは次のとおりです。
allowed(resourceid, personid)
person(personid, email)
人がリソースにアクセスする権利を持っているかどうかを出力したいのですが、resourceid = 2 としましょう。結果は次のようになります。
personright(personid, email, resourceid)
リソース 2 へのアクセスが許可されていない場合、resourceid は null である必要があります。リソース 2 へのアクセスが許可されている場合、resourceid は 2 である必要があります。
したがって、クエリが実行されるたびに、ユーザー リスト全体が出力されることを期待しています。
サブクエリを使用した実用的なソリューションがありましたが、これを結合で実行したいと考えています。
select person.personid, person.email, allowed.resourceid
from person
right join allowed on(person.personid = allowed.personid)
where (allowed.resourceid IS NULL OR allowed.resourceid = 2);
これが機能しないのはなぜですか?