What is an Alias?
Advantages of Using Alias
Syntax
SELECT column AS AliasName FROM TableName
AS
.Examples
Basic Usage:
SELECT ID, Name, City FROM Student AS St WHERE Age > 18;
St
is an alias for the table Student
.Concatenation Example:
SELECT FirstName || ' ' || LastName AS FullName FROM Employee;
FirstName
and LastName
with a space, assigning the result the alias FullName
.Aggregate Function Example:
SELECT AVG(Salary) AS AvgSal FROM Employee;
AvgSal
.Examples of Alias Usage
Query Example without Alias:
SELECT FirstName || LastName FROM Employee;
Improved Query with Alias and Space:
SELECT FirstName || ' ' || LastName AS FullName FROM Employee;
FullName
with proper format.Handling Aggregate Functions:
SELECT AVG(Salary) AS AvgSal FROM Employee;
AvgSal
for the column containing average salary values.Alias for Table:
SELECT ID, Name, Department FROM Employee AS _temp;
Employee
is referenced as _temp
.