Last answered:

01 Jul 2025

Posted on:

29 Jun 2025

0

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)
Instructor
Posted on:

01 Jul 2025

0
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 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

Submit an answer