4 ms·
I've stopped using aliases in the SQL I write and it's dramatically increased the clarify. From this style guide, the aliases section would look like this in m
by jkubicek 2y ago
I've stopped using aliases in the SQL I write and it's dramatically increased the clarify.
From this style guide, the aliases section would look like this in my style guide:
SELECT first_name
FROM staff
JOIN students
ON students.mentor_id = staff.staff_num;
- Sn0wCoder 2y agoIf the table names are all short one word like that, they are already basically aliases. What do you do when you end up on some legacy project (you did not make the schema) where_the_table_names_look_like_this? Seems some sort of alias might be more appropriate. Also, when you are writing longer / sub queries or using Common Table Expressions it’s impossible to not use an alias.
- jkubicek 2y agoActually, what I should have said was, "I've stopped using alias by default for every table reference". I'm not opposed to aliases, it's just no longer something I do by default.
- otteromkram 2y agoHow do you know which table first_name came from? Also aliasing can be as much for legibility as anything. SELECT ZZ.first_name FROM staff AS ZZ INNER JOIN students AS Q ON Q.mentor_id = ZZ.staff_num;
- Izkata 2y agoWithout aliases makes each part understandable without having to jump around and hold extra context in your head: SELECT staff.first_name FROM staff INNER JOIN students ON student.mentor_id = staff.staff_num; Whether or not you agree on the exact number [0], humans have limited working memory and aliases that don't group up concepts use it up unnecessarily. [0] https://en.m.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two https://en.m.wikipedia.org/wiki/The_Magical_Number_Seven,_Pl...
- asdfasvea 2y agoAgree. In my experience people use aliases to use aliases. They know them but don't understand them. Aliases are the SQL equivalent of ternary operators. Are you trying to write clean code or are you trying to express to other people you know things?