Suppose we have tables Appointments
, Patients
, and Doctors
, and every record in Appointments
is related to Patients
and Doctors by patient_id
and doctor_id
. What's the difference between these two queries. What are the advantages and disadvantages of either of them:
1:
SELECT Patients.first_name,Patients.last_name,Patients.patient_id,
Doctors.first_name, Doctors.last_name,Doctors.doctor_id,
Appointments.app_length,Appointments.app_datetime
FROM Appointments,Patients,Doctors
WHERE Appointments.doctor_id=Doctors.doctor_id
AND Appointments.patient_id=Patients.patient_id
2:
SELECT Patients.first_name,Patients.last_name,Patients.patient_id,
Doctors.first_name, Doctors.last_name,Doctors.doctor_id,
Appointments.app_length,Appointments.app_datetime
FROM Patients INNER JOIN Appointments ON Appointments.patient_id=Patients.patient_id
INNER JOIN Doctors ON Appointments.doctor_id=Doctors.doctor_id
It's good to know that both of them work and give the same results. But I want to know the difference and which one is more optimized on a huge amount of data.