我正在处理一个与Oracle
连接的PHP页面
。我遇到了以下SQL语句,但不确定它是否能实现预期目标,所以想在这里请教一下。被问及的SQL语句是:
select tableA.id, tableA.name, tableB.details
from tableA
left join tableB on
tableB.id = tableA.id
and
tableB.logId = '<logged_in_user>'
现在,当我以一个没有在tableB表中的条目的用户身份登录时,这个查询运行时仍然会返回记录。我的假设是,这个子句应该是'where'
而不是'and'
。
left join tableB on
tableB.id = tableA.id
where
tableB.logId = '<logged_in_user>'
我有两个问题。
- 我的理解是正确的吗?
- 如果是正确的,那么这个查询为什么会返回结果?'and'子句在检查什么?
请问有人能够解释一下上述查询中使用AND和WHERE之间的区别吗?
谢谢!
left join tableB on ... where tableB.logId = ...
总是错误的。 - user359040