vendredi 16 octobre 2015

How to get the data that is included in a table but not in another table,when must add "where" with "LEFT ON"

SELECT CaseFolder.CaseId, CaseFolder.CaseCoverImageFileName,
            CaseFolder.CaseName, count(Event.CaseId), CaseFolder.CaseColor,
            CaseFolder.IsMedicalCase, CaseFolder.StartDate, CaseFolder.EndDate
    FROM CaseFolder
    LEFT JOIN Event ON CaseFolder.CaseId = Event.CaseId
    WHERE Event.PersonId = 1 AND Event.IsDeleted = 0 AND CaseFolder.IsDeleted = 0
    GROUP BY CaseFolder.CaseId 

I select Count by tableEvent and another by table CaseFolder.The primary key is CaseId,But I need to select data that is included in a table but not in another table,when must add "where" with "LEFT ON".If I delete the sql codeWHERE Event.PersonId = 1 AND Event.IsDeleted = 0 AND CaseFolder.IsDeleted = 0 the result is right.Because the WHERE contains conditions that can't suit in tableCaseFolder.what should i do?

Aucun commentaire:

Enregistrer un commentaire