データベースに保存されているセクションのリストをSections
列 ( sectionId, sectionTypeId, sectionName
) のテーブルに、特権のリストを列 ( ) のテーブルUserPrivilages
に持っていますuserPrivilagesId, userId, sectionTypeId
。
テーブルからすべてのセクションを選択したいのですが、 by に保存されてSections
いるものをマークします。sectionTypes
sectionTypeId
UserPrivilages
userId
何かのようなもの:
SELECT sectionId, sectionTypeId, sectionName, (true/false) as privilage
FROM Sections
これをテーブルに結合UserPrivilages
すると、両方のテーブルにのみ存在する結果が得られますが、ユーザーがt have
権限を付与するセクションも必要です。
この true/false は、 from テーブルがテーブルに存在するUserPrivilages
場合はsectionTypeId
fromテーブルであり、それ以外の場合は false を返します。Sections
UserPrivilages
userId
したがって、結果はたとえば
SectionId sectionTypeId sectionName privilage
1 1 Name1 true or 1
2 2 Name2 false or 0