0
0
SQLquery~5 mins

Column aliases with AS in SQL

Choose your learning style9 modes available
Introduction

Column aliases let you rename columns in your query results to make them easier to read or understand.

When you want to give a column a friendlier or more descriptive name in the output.
When you use calculations or functions and want to name the result column clearly.
When you join tables and want to avoid confusing column names.
When you want to format the output for reports or user interfaces.
Syntax
SQL
SELECT column_name AS alias_name FROM table_name;
The keyword AS is optional but helps make the alias clear.
Alias names can be enclosed in quotes if they contain spaces or special characters.
Examples
This renames the column first_name to name in the output.
SQL
SELECT first_name AS name FROM employees;
This calculates yearly salary and names the result annual_salary.
SQL
SELECT salary * 12 AS annual_salary FROM employees;
This uses quotes to allow a space in the alias name.
SQL
SELECT last_name AS "Last Name" FROM employees;
Sample Program

This query selects the first three employees, renaming first_name to Name and salary to MonthlySalary.

SQL
SELECT first_name AS Name, salary AS MonthlySalary FROM employees LIMIT 3;
OutputSuccess
Important Notes

Aliases only change the column name in the output, not in the actual table.

Use aliases to make your query results easier to understand for others.

Summary

Column aliases rename columns in query results.

Use AS keyword to assign an alias, but it is optional.

Aliases improve readability and clarity of output.