有人可以告诉我哪种方法更好,它们都产生相同的结果,但哪个更“正确”?哪个查询是正确的方法?
就我个人而言,我觉得第一个查询更容易阅读,但我似乎在其他地方阅读别名应始终使用。
由于
SELECT Patient.PatientSurname, Doctor.DoctorSurname
FROM Patient
JOIN Operation
ON Operation.PatientCode=Patient.PatientCode
JOIN Doctor
ON Doctor.DoctorCode=Operation.DoctorCode
WHERE Operation.OperationType='Broken Arm'
GROUP BY Patient.PatientSurname
HAVING count(Patient.PatientSurname) > 0
SELECT PatientSurname, DoctorSurname
FROM Patient as p, Operation as o, Doctor as d
WHERE o.PatientCode=p.PatientCode
AND d.DoctorCode=o.DoctorCode
AND o.OperationType='Broken Arm'
GROUP BY p.PatientSurname
HAVING count(p.PatientSurname) > 0
这是一个主观问题,所以可能不适合SO。不过,我建议阅读[Aaron Bertrand]撰写的这些文章(http:// stackoverflow。com/users/61305/aaron-bertrand) - > [使用类似于a,b,c的表格别名](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to -kick-using-table-aliases-like-abc-or-t1-t2-t3.aspx),[Using Old Style Joins](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08) /bad-habits-to-kick-using-old-style-joins.aspx) – GarethD