我想知道如果你可以幫助 - 我有一個SQL查詢(SQLServer),我已經創建,雖然一些結果沒有被顯示,我認爲它由於NULL一些連接的結果。例如,我知道一些連接將使用NULL結果,因爲100.resp_unit_no可能是NULL,也可能是100.employee_no。SQL查詢結果中連接有NULL結果
查詢到目前爲止是:
select
058.DESCRIPTION "IRU",
111.job_ref "Job Reference",
117.DESCRIPTION "Status",
108.STATUS "Fixed?",
105.DESCRIPTION "Job Type",
111.POSTCODE "Postcode",
111.site_id "Site ID",
108.CONTRACT_START "Contract Earliest",
108.CONTRACT_COMPLETION "Contract Latest",
108.BOOKED_DURATION "Planned Duration (mins)",
111.IMPORTANCE "Importance",
111.CUSTOMER_NAME "Customer Name",
100.expected_start "Expected Start",
100.expected_end "Expected End",
210.NAME "Employee",
111.ON_HOLD "On Hold?"
FROM
111_JOBS 111,
108_JOB_DETAILS 108,
058_RESPONSIBILITY_UNITS 058,
100_ACTIVITIES 100,
105_ACTIVITY_TYPES 105,
210_EMPLOYEES 210,
117_STATUS_DESCRIPTIONS 117
where 111.JOB_NO=108.JOB_NO
AND 111.JOB_NO=100.JOB_NO
AND 100.RESP_UNIT_NO=058.RESP_UNIT_NO
AND 111.JOB_TYPE=105.ACTIVITY_TYPE
AND 210.EMPLOYEE_NO=100.EMPLOYEE_NO
AND 117.STATUS=100.ACTIVITY_STATUS
order by IRU, Employee, EXPECTED_START;
我想我需要一個右外連接,但我不能完全得到結構正確...
任何幫助將不勝感激!
請勿使用數字作爲別名!並閱讀有關連接和正確的連接語法:http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html您的查詢是否運行? – fancyPants
它運行 - 除了employee_no和resp_unit_no爲空之外的結果回來。 我確實在數字前面有字符 - 它只是我的公司名稱,我不想發送該字符:) –