有人可以告訴我哪種方法更好,它們都產生相同的結果,但哪個更「正確」?哪個查詢是正確的方法?
就我個人而言,我覺得第一個查詢更容易閱讀,但我似乎在其他地方閱讀別名應始終使用。
由於
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