This question already has an answer here:
The result should look like:
Doctors_have_no_patients
Doctor2
Doctor3
Doctor5
THE TABLES
Doctor table called `Doctors`
**DoctorID**
Doctor1
Doctor2
Doctor3
Doctor4
Doctor5
Booking table called `Bookings`
PatientID DoctorID Date
Patient1 Doctor1 etc.
Patient2 Doctor4 etc.
Patient3 Doctor1 etc.
Should I use distinct
or something? Like:
select Bookings.DoctorID as Doctors_have_no_patients count(distinct(Bookings.PatientID))...
</div>
You can use not in (and no distinct in this case)
Number of doctors without patients
select count(*) from Doctors
where DoctorId not in (select doctorID from bookings);
Id of doctors
select DoctorID from Doctors
where DoctorId not in ( select doctorID from bookings);
Use the following query
SELECT * from `Doctors`
WHERE `DoctorID` NOT IN (SELECT DISTINCT(`doctorID`) FROM `bookings`);