我在使用 sql 查询时遇到了一些问题。以下查询返回权限结果。它返回表中男性、说瑞典语并且在第 4 组中的成员。
SELECT DISTINCT Member.ID
FROM Member
LEFT OUTER JOIN Experience ON Experience.MemberID = Member.ID
LEFT OUTER JOIN Qualification ON Qualification.MemberID = Member.ID
LEFT OUTER JOIN Language On Language.MemberID = Member.ID
LEFT OUTER JOIN Member_Interests ON Member_Interests.MemberID = Member.ID
LEFT OUTER JOIN Group_Members ON Group_Members.MemberID = Member.ID
WHERE 1=1 AND Gender = 'male' AND Language.Name IN ( 'Swedish' ) AND Group_Members.GroupID = 4
但是,如果我排除直接在成员表上搜索的其他 where 条件,则 language.Name 将被忽略。IE。
SELECT DISTINCT Member.ID
FROM Member
LEFT OUTER JOIN Experience ON Experience.MemberID = Member.ID
LEFT OUTER JOIN Qualification ON Qualification.MemberID = Member.ID
LEFT OUTER JOIN Language On Language.MemberID = Member.ID
LEFT OUTER JOIN Member_Interests ON Member_Interests.MemberID = Member.ID
LEFT OUTER JOIN Group_Members ON Group_Members.MemberID = Member.ID
WHERE 1=1 AND Language.Name IN ( 'Swedish' ) AND Group_Members.GroupID = 4
上面的查询返回组 4 中的所有成员。瑞典语部分被简单地忽略,只要语言表中有一个名为瑞典语的语言,则返回所有用户。如果语言不在表中,则不返回任何用户。
我希望第二个查询只返回第 4 组中讲瑞典语的所有成员。有谁知道为什么这没有发生?