假设我们有表Appointments
,Patients
和Doctors
,Appointments
中的每条记录都与Patients
和patient_id
的医生相关}和doctor_id
。这两个查询之间有什么区别。其中任何一个的优点和缺点是什么:
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
很高兴知道它们都有效并且给出相同的结果。但是我想知道差异以及哪一个在大量数据上更加优化。