通过WHERE子句从多个表中使用INNER JOIN或_multi select_时有什么区别?

时间:2013-07-30 22:29:31

标签: sql select inner-join where-clause

假设我们有表AppointmentsPatientsDoctorsAppointments中的每条记录都与Patientspatient_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

很高兴知道它们都有效并且给出相同的结果。但是我想知道差异以及哪一个在大量数据上更加优化。

0 个答案:

没有答案