1

我有这张表,其中包含特定客户订单的所有附件,我只想选择一种附件,但即使没有附件,我也想查看该行。有没有办法这样做?

我试过这个但它不起作用:

SELECT 
  Comm.No_Com, 
    CASE WHEN Attachement.EntityID IS NULL OR Attachement.ATS_CategoryOfAttachmentCode='DESSIN'
        THEN Attachement.FileName
        ELSE ' '
    END AS Dessin

    FROM Comm
    INNER JOIN Attachement
    ON Comm.COH_Id=Attachement.EntityID
4

1 回答 1

2

使用 LEFT OUTER JOIN 而不是 INNER JOIN。

SELECT 
    Comm.No_Com, 
    CASE WHEN Attachement.EntityID IS NULL OR Attachement.ATS_CategoryOfAttachmentCode='DESSIN'
        THEN Attachement.FileName
        ELSE ' '
    END AS Dessin
FROM Comm
LEFT OUTER JOIN Attachement
ON Comm.COH_Id=Attachement.EntityID AND Attachment.Kind = 'DesiredKind'
于 2013-07-08T19:01:37.563 回答