我有这个表格,其中包含我对特定客户订单的所有附件,我想只选择一种附件,但即使没有附件,我也希望看到该行。有办法吗?
我尝试了这个,但它不起作用:
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
答案 0 :(得分: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'