19. Using Aliases with AS
Core Idea: The AS keyword assigns temporary names to query output columns or source tables, improving readability and disambiguating identical column names across joins.
Column Aliases
Table Aliases in Joins
Aliases with Spaces & Reserved Words
Wrap alias names in square brackets [...] or double quotes if they contain spaces or match SQL keywords:
Advanced Deep Dive ADVANCED
Mandatory for Expressions: Computed columns, aggregate outputs, or subquery expressions require aliases if they will be accessed via derived tables or views.
Logical Processing Order: Column aliases defined in SELECT cannot be referenced in the WHERE or HAVING clause because WHERE is evaluated before SELECT. However, aliases can be used in ORDER BY.
Performance Impact: Aliasing is purely a syntactic construct evaluated at compile time; it incurs zero runtime performance overhead.
Self-Joins: Table aliases are strictly required when performing self-joins to reference the same table on both sides of a relationship.