我確實意識到我面臨的問題不是火箭科學,但仍然沒有找到任何關於解決此問題的信息。SQL Select語句 - 多個表格允許空值
我在我的數據庫中有多個表(PSQL
)我想創建一個select
查詢來爲我的應用程序生成報告功能。
這裏是我的查詢:
select
s.id, s.name, st.name, p.firstname || ' ' || p.lastname,
f.name, f.store_date, bdt.name, bd.comment
from
system s, systemstatus st, role w, person p, file f,
documenttype bdt, document bd
where
w.system_id = s.id and
p.id = w.person_id and
st.id = s.status_id and
bd.system_id = s.id and
bd.file_id = f.id and
bd.type_id = bdt.id and
bd.role_id = w.id;
查詢工作,我得到300
行完全充滿值我正在尋找。問題是我在System
表中有大約1000
行。有可能沒有Person
或Document
這可能與特定System
連接。
我想看到的是在我System
表中所有行(我的意思是約1000),當我不能System
鏈接Person
或Document
我希望字段爲空(現在它不顯示全部)
[不良習慣踢:使用舊式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style- joins.aspx) - 在ANSI - ** 92 ** SQL標準中**舊式*逗號分隔的表*樣式列表已替換爲* proper * ANSI'JOIN'語法(**超過20年**前),其使用是不鼓勵 –