Aliases let you rename a table or a column temporarily in your query result. This is helpful to make column names more readable or to shorten table names in complex queries.
Use the AS
keyword or just a space to create an alias for a column.
SELECT first_name AS 'Name', salary AS 'Monthly Salary' FROM employees;
The columns first_name
and salary
will appear as Name and Monthly Salary in the results.
Aliases are especially useful when you use joins or subqueries. You can rename tables to shorter names for easier referencing.
SELECT e.first_name, d.department_name FROM employees AS e JOIN departments AS d ON e.department_id = d.department_id;
Here, employees
is aliased as e
and departments
as d
for simpler referencing.
AS
keyword and just write column_name alias_name
.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!