mlee1steph
Programmer
Hi Everyone,
I have a query that needs to pull data out of 3 tables. Nothing to hard so far. Here the query:
SELECT Patients.PatientId, TERMINATION.DOA, TERMINATION.DOT, PATIENTS.PatientID, PATIENTS.LastName, PATIENTS.FirstName, PATIENTS.COUNSELOR, PATIENTS.MEDICAID_ID, PATIENTS.DOB, COUNSELORS.C_LastName + ', ' + COUNSELORS.C_FirstName as CName
FROM (PATIENTS LEFT JOIN TERMINATION ON PATIENTS.PatientID = TERMINATION.PatientID)
LEFT JOIN COUNSELORS ON PATIENTS.COUNSELOR = COUNSELORS.C_ID
WHERE ActiveClient = 1
order by NAME
Ok, The problem with this query is that the Termination table can contains more that one record for each PatientId, so the result of this query is that if there are 2 records in the Termination table I get two records in the result. I only want ONE record for each Patient. More specifically I will need to look at the TERMINATION.DOA field and get the newest date (this field is a datetime field). Does anyone have any suggestions. Thanks for any help.
Michael
I have a query that needs to pull data out of 3 tables. Nothing to hard so far. Here the query:
SELECT Patients.PatientId, TERMINATION.DOA, TERMINATION.DOT, PATIENTS.PatientID, PATIENTS.LastName, PATIENTS.FirstName, PATIENTS.COUNSELOR, PATIENTS.MEDICAID_ID, PATIENTS.DOB, COUNSELORS.C_LastName + ', ' + COUNSELORS.C_FirstName as CName
FROM (PATIENTS LEFT JOIN TERMINATION ON PATIENTS.PatientID = TERMINATION.PatientID)
LEFT JOIN COUNSELORS ON PATIENTS.COUNSELOR = COUNSELORS.C_ID
WHERE ActiveClient = 1
order by NAME
Ok, The problem with this query is that the Termination table can contains more that one record for each PatientId, so the result of this query is that if there are 2 records in the Termination table I get two records in the result. I only want ONE record for each Patient. More specifically I will need to look at the TERMINATION.DOA field and get the newest date (this field is a datetime field). Does anyone have any suggestions. Thanks for any help.
Michael