I have a patient lab database created by a colleague in MS Access that has 4 tables.
Table 1 contains Patient Demographics (Patient ID, Gender, DOB, etc.)
Table 2 contains Type1 (Blood Pressures, Heart rate)
Table 3 contains Type2 (Chemistry panel, hemoglobin, etc.)
Table 4 contains Type3 (Microbiology culture results)
Each table has an internal patient number in common. Each measure can be taken independently of the other, and may or may not have results. What I would like is a simple table that pulls an external patient ID, gender and DOB only found in Table 1, combined with the DATE of results from each of the other tables. I tried using RIGHT joins and expected there to be 'null' values when there was no match on dates in subsequent tables. Instead I have a result that looks like a cross-tab query and each row has a value for each. Obviously I am not understanding the use of JOINS correctly. This is what I tried:
SET DATEFORMAT dmy
DECLARE @time time(0)
Select DISTINCT
P.PATIENT_ID as 'Patient ID',
P.SEX as 'Sex',
CONVERT(VARCHAR(11),P.DOB) as 'DOB',
CONVERT(VARCHAR,TYPE1.DateTime,101)as 'BP Measure DATES',
CONVERT(VARCHAR,TYPE2.DateTime,101) as 'CHEM Measure DATES',
CONVERT(VARCHAR,TYPE3.DateTime,101) as 'MICRO Measure DATES'
From dbo.PATIENT as P LEFT JOIN dbo.BRACHIALBPS as TYPE1 on P.PATIENT_NO=TYPE1.PATIENT_NO
Right Join dbo.Chemistries as TYPE2 on P.PATIENT_NO=TYPE2.PATIENT_NO
Right Join dbo.Microbiologies as TYPE3 on P.PATIENT_NO=TYPE3.PATIENT_NO
ORDER BY P.PATIENT_ID
I am using SQL Server 2008 to import the data and execute the query.
As I mentioned I was hoping to have one row per patient/per result date. But I am getting multiple rows for EVERY date combination.
Thanks in advance for any guidance!