G-3120: Always use table aliases when your SQL statement involves more than one source.
Blocker
Maintainability
Reason
It is more human readable to use aliases instead of writing columns with no table information.
Especially when using subqueries the omission of table aliases may end in unexpected behavior and result.
Example (bad)
1 2 3 4 5 6 7 |
|
If the jobs
table has no employee_id
column and employees
has one this query will not raise an error but return all rows of the employees
table as a subquery is allowed to access columns of all its parent tables - this construct is known as correlated subquery.
1 2 3 4 5 6 7 8 |
|
Example (better)
1 2 3 4 5 6 7 |
|
Example (good)
Using meaningful aliases improves the readability of your code.
1 2 3 4 5 6 7 |
|
If the jobs
table has no employee_id
column this query will return an error due to the directive (given by adding the table alias to the column) to read the employee_id
column from the jobs
table.
1 2 3 4 5 6 7 8 |
|