[英]SQL query to check based on if exists condition
我需要有關 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 獲取數據。 如果它存在,那么當然應該包括 emp.pr.id = pr.id。
提前致謝
這就是你所說的:
select employee.*, stream.*, priority.* from employee emp, stream st, priority pr --> priority is not mandatory where emp.st.id = st.id and str.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(+)
有關左/右外連接的更多詳細信息,您可以查看以下鏈接。 https://docs.oracle.com/cd/B28359_01/server.111/b28286/queries006.htm#SQLRF52331
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.