返回其他列的NULL值的PK(Situs ID)

时间:2017-03-08 12:36:15

标签: sql sql-server null left-join inner-join

我想返回主键([Situs ID]),帐号和LoanPool,即使异常类别,异常注释,异常代码或异常描述都有NULL值。

我正在考虑将左连接与内连接结合使用,但无法确定将其放在何处。

SELECT        Questionnaire_Responses.LoanId AS [Situs ID], Loans.MainAccountNumber AS [Account Number], Loans.LoanPool, Exceptions.ExceptionCat AS [Exception Category],
                      Questionnaire_Responses.Comments AS [Exception Comments], Exceptions.Code AS [Exception Code], Exceptions.ExceptionText AS [Exception Description]
FROM            Questionnaire_Responses INNER JOIN
                     Exceptions ON Questionnaire_Responses.ExceptionId = Exceptions.Id INNER JOIN
                     Loans ON Questionnaire_Responses.LoanId = Loans.Id INNER JOIN
                     Questions ON Questionnaire_Responses.QuestionId = Questions.Id INNER JOIN
                     Questionnaires ON Questions.QuestionnaireId = Questionnaires.Id INNER JOIN
                     Loans_Questionnaires_Mapping ON Loans.Id = Loans_Questionnaires_Mapping.LoanId AND 
                     Questionnaires.Id = Loans_Questionnaires_Mapping.QuestionnaireId
WHERE        (Loans.Id IN (1,2,3,4)) AND (Questions.Active = 1) AND (Questionnaires.Active = 1) 
ORDER BY [Situs ID], [Exception Description], [Exception Code]

Current Results

Desired Results

1 个答案:

答案 0 :(得分:0)

td