SELECT
Department.Name,
COUNT(Employees.EmployeeID)
FROM Department
JOIN Employees
ON Employees.DepartmentID = Department.DepartmentID
GROUP BY Department.Name
HAVING COUNT(Employees.EmployeeID) < 3 SELECT
Department.Name,
COUNT(Employees.EmployeeID)
FROM Department
JOIN Employees
ON Employees.DepartmentID = Department.DepartmentID
GROUP BY Department.Name
HAVING COUNT(Employees.EmployeeID) < 3I'd rather see:
EmployeeReferences eFrom JOIN EmployeeReferrals eTo
...and then see ON eFrom.ID = eTo.ID
...
JOIN xyz
ON eFrom.Source = ...
rather than have to read acres of EmployeeRe-something 4 or 5 times through an 8-table BI join.Similarly, I've had to deal with (admittedly legacy) tablenames like A12R18SALE and A12B14PROD. Aliases come in really handy there.
* I always specify columns as table.column, not just column as it makes things explicit where the could be ambiguity if a less experienced coder is looking (I know that column reference in a correlated sub-query refers to the most local instance of that table, but having the table name there explicitly states that referring to that was my intention and not an accident). Having short aliases saves typing in this instance (though not too short/arbitrary - the object names should still be meaningful in the context of the query: a, b, c, d, ... would generally be bad aliases)
* If the query gets more complex and needs to join objects in that have columns of the same names as those in existing objects (especially if you add another reference to an object already in use in this query), you've already got the aliases there for the first instance reducing the chance you'll get one wrong when adding them in for both instances of the same name.