My table structure is as follows
Endoscopy:
PK:Endoscopy_Id
FK:PatientId
This is many to one with...
Patient
PK:Patient_Id
This is one to many with Endoscopy and with Histology
Histology
PK:Histology_Id
FK:PatientId
This is one to many with
HistologyDetails
PK:HistologyDet_Id
FK:Histology_Id
I am trying to perform a query which will extract all the 'astroscopies' and some fields from histology and histologydetails for all the patients. At the moment I am not getting all the results and I am not sure why. I am using:
SELECT 
    Endoscopy.*, 
    Histology.Diagnosis, Histology.NatureOfSpec, 
    Histology.Histology, 
    HistolDetails.MeasurementLargest, HistolDeatils.NumberBx 
FROM 
    Endoscopy  
JOIN 
    PatientData ON Endoscopy.HospNum_Id = PatientData.HospNum_Id   
JOIN 
    Histology ON Histology.HospNum_Id = PatientData.HospNum_Id  
JOIN
    HistolDetails ON Histology.Histology_Id = HistolDetails.Histology_Id
WHERE 
    histology.VisitDate = endoscopy.VisitDate 
    AND (ERFINDINGSSTR LIKE '%Barret%'OR ERDIAGNOSISSTR LIKE '%Barret%') 
    AND Endoscopy.ERPROCEDUREPERFORMED LIKE '%astroscopy%'
Aucun commentaire:
Enregistrer un commentaire