显示应忽略的行的MySQL查询
所以我不知道我错过了什么?当我运行此查询时,我得到的是许可证id不是3767的行以及具有3767的正确行。如果我说“where users_licenses.license_id=3767”,我应该只收到license_id为3767的记录,对吗显示应忽略的行的MySQL查询,mysql,sql,Mysql,Sql,所以我不知道我错过了什么?当我运行此查询时,我得到的是许可证id不是3767的行以及具有3767的正确行。如果我说“where users_licenses.license_id=3767”,我应该只收到license_id为3767的记录,对吗 select * from users join users_licenses on users_licenses.user_id = users.id join groups on groups.id = users.group_id WHERE
select * from users
join users_licenses on users_licenses.user_id = users.id
join groups on groups.id = users.group_id
WHERE users_licenses.license_id = 3767 and groups.id = 6325 or groups.id = 6343
现在它是带有or语句的,因为当它只是一个组ID时,它就工作了。但为什么第二个where子句中的or仍然重要呢?我仍然应该只接收许可证id为3767的行,使用括号,直到您习惯了
和和或的工作方式。
您的where
子句被解析为:
WHERE (users_licenses.license_id = 3767 and groups.id = 6325) or
groups.id = 6343
这似乎不是你的意图
但是,在这种情况下,您可以使用
中的简化筛选:
where users_licenses.license_id = 3767 and groups.id in (6325, 6343)
使用括号,直到您习惯了和以及或的工作方式。
您的where
子句被解析为:
WHERE (users_licenses.license_id = 3767 and groups.id = 6325) or
groups.id = 6343
这似乎不是你的意图
但是,在这种情况下,您可以使用
中的简化筛选:
where users_licenses.license_id = 3767 and groups.id in (6325, 6343)
抱歉,在我等着接受回答之前,他已经开始午休了。抱歉,在我等着接受回答之前,他已经开始午休了