Sql-Server
SELECT w/ INNER JOIN 查詢可選列
我有五個表:
File2
、Branches_of_Study
、Schools
、Education_Establishments
和Certificates
。File2
是事務表,所有其他表作為參考表。
File2
都是關於員工的教育背景的。員工必須首先從站點的下拉列表中選擇教育機構,例如Highschool
,College
等。學習分支是指員工參加的課程,例如,,IT
等。HRM``Photography
選擇後
College
,員工必須選擇一個Branch of Study
。但是在選擇時Highschool
,不允許選擇一個研究分支。我在網站上有一個顯示所有員工教育程度的網格視圖。這是我的查詢:
SELECT File2.file2_id, File2.candidate_id, ee.education_establishment, s.school, File2.school_others, File2.start_date, File2.end_date, bs1.branch_of_study AS branch_of_study_1, c.certificate, File2.course_appraisal, bs2.branch_of_study AS branch_of_study_2 FROM File2 INNER JOIN Education_Establishments ee ON File2.education_establishment_code = ee.education_establishment_code INNER JOIN Schools s ON File2.school_code = s.school_code INNER JOIN Branches_of_Study bs1 ON File2.branch_of_study_1_code = bs1.branch_of_study_code INNER JOIN Branches_of_Study bs2 ON File2.branch_of_study_2_code = bs2.branch_of_study_code INNER JOIN Certificates c ON File2.certificate_code = c.certificate_code WHERE File2.candidate_id = 100003
該查詢僅返回
College
員工編號條目的結果100003
。我認為這是由條目欄位中null
的值引起的。Branch of Study``Highschool
我想要一個查詢,它將顯示所有條目(
College
和Highschool
),同時顯示參考表中的文本值(不是程式碼)。
如果連接是“可選的”,那麼根據定義,它不是內部連接。考慮調查左連接。