SQL Query join problem
Hi,
I have two tables in my db, the patient table holds details of patients, the contact table holds details of contacts related to the patient.
patient table
patientid - primary key - int
patient name - varchar
contact table
contactid - primary key - int
patientid - foreign key from patient table - int
incontact - foreign key from paient table to relate contacts - int
My contact table has the following data:
contactid patientid incontact
2 19 21
2 19 22
I can retrieve data for the patients that have been in contact with patientid 19, by using the following join:
SELECT * FROM PATIENT
LEFT JOIN incontact
ON incontact.incontact = patient.patientid
WHERE incontact.patientid = 19
However, can you please tell me how I can get data from the patients table where the incontact is 21?
So I can get contacts from patients and patients from contacts?
Thankyou