I have 3 tables Doctor, Patient and Visit.
Doctor Table has DoctorID, Name and City.
Patient Table has PatientID, Name and City.
Visit Table has DoctorID, PatientID, NumVisits.
I am trying to retrieve all Doctors that have not been visited by a Patient of a Certain City (Lets say New York).
I am very new at writing queries and I can't seem to get it to work.
My CODE:
SELECT DoctorId, Doctor.Name FROM Visit JOIN Doctor using(DoctorID) JOIN Patient using(PatientID) WHERE NOT EXISTS (SELECT DoctorId, Doctor.Name FROM Visit JOIN Doctor using(DoctorID) JOIN Patient using(PatientID) WHERE Patient.City = 'New York'); Can someone please explain to me what I am doing wrong? Maybe my whole approach is not correct.
neverperform more joins than there are tables involved in your query!!!