基于是否存在条件检查的SQL查询
我需要一个sql查询的帮助,如果条件存在或不存在,我想在这里获取数据基于是否存在条件检查的SQL查询,sql,oracle,Sql,Oracle,我需要一个sql查询的帮助,如果条件存在或不存在,我想在这里获取数据 select employee.*, stream.*, priority.* from employee emp, stream st, priority pr where emp.st.id = st.id and str.pr.id = pr.id 所以这里的优先权不是强制性的。值可能存在,也可能不存在。因此,如果优先级不存在,则应为emp.st.id=st.id获取数据。若它存在,那个么当然应
select employee.*, stream.*, priority.*
from employee emp,
stream st,
priority pr
where emp.st.id = st.id
and str.pr.id = pr.id
所以这里的优先权不是强制性的。值可能存在,也可能不存在。因此,如果优先级不存在,则应为emp.st.id=st.id获取数据。若它存在,那个么当然应该包括emp.pr.id=pr.id
提前感谢这是您所说的: 将其从英文翻译为SQL,读作“外部连接”,这意味着类似这样的内容可能会满足您的需要:
select e.*,
s.*
p.*
from employee e join stream s on s.id = e.st_id
left join priority p on p.id = s.pr_id --> this
我希望下面的建议能对你有所帮助
select employee.*, stream.*, priority.*
from employee emp,
stream st,
priority pr
where emp.st.id = st.id
and str.pr.id = pr.id(+)
有关左/右外部联接的更多详细信息,请查看下面的链接。
今天的提示:切换到现代的显式
JOIN
语法!更容易写(没有错误),更容易阅读和维护,如果需要,更容易转换为外部连接!你能提供一些例子吗?我有多个表相互连接。在这里,流和雇员是连接的,流优先级是连接的。在这种情况下,我如何派生一个条件向我们显示一些示例表数据和预期结果-全部为格式化文本(无图像)。
select employee.*, stream.*, priority.*
from employee emp,
stream st,
priority pr
where emp.st.id = st.id
and str.pr.id = pr.id(+)