Resolved: Omission of table indication: a general rule
"You can omit the table indication in the GROUP BY section if the column name is encountered only once throughout the joined tables"
My question:
Is this generally true for all columns in all parts of the query? For example, I noticed that there is AVG(salary) instead of AVG(s.salary) and the query still works.
1 answers ( 1 marked as helpful)
Hi Dimiter!
Thanks for reaching out.
Yes, this is generally true: if a column name is unambiguous—i.e., it appears in only one table in the query—you can omit the table alias or name in any part of the SQL statement, including
Hope this helps.
Best,
Tsvetelin
Thanks for reaching out.
Yes, this is generally true: if a column name is unambiguous—i.e., it appears in only one table in the query—you can omit the table alias or name in any part of the SQL statement, including
SELECT
, GROUP BY
, ORDER BY
, etc. Functions like AVG(salary)
work without s.salary
as long as no other table in the query has a salary column. However, for clarity and to avoid future errors in complex queries, many developers still prefer to include the table alias.Hope this helps.
Best,
Tsvetelin