August 14, 2009 at 10:05 am
Why does everyone think that table aliases are a necessary part of the syntax? They are not.
SELECT Emp.Empid, Emp.EmpFirstName, Emp.EmpLastName, Dept.DepartmentName
FROM Employee Emp
INNER JOIN Department dept
ON Emp.Departmentid=Dept.Departmenttid
It's easier to read this as:
SELECT Employee.Empid, Employee.EmpFirstName, Employee.EmpLastName, Department.DepartmentName
FROM Employee
INNER JOIN Department
ON Employee.Departmentid=Department.Departmenttid
Some people will complain about "all the typing". However, I don't believe for one second that the speed of writing SQL code is constrained by HOW FAST you can type. It's how fast you can design and think that is the limiting factor! Besides, copy and paste are your friends.
The next thing you know, you'll be using one-letter table aliases, even in complex queries, and then the code is VERY hard to read later on. Table aliases are SOMETIMES required, but not in simple joins like this. PLEASE don't teach people in "SQL 101" to use table aliases in simple joins. Code readability is far too important. Please!
David Walker
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply