Introduction
Column aliases let you rename columns in your query results to make them easier to read or understand.
Column aliases let you rename columns in your query results to make them easier to read or understand.
SELECT column_name AS alias_name FROM table_name;
first_name to name in the output.SELECT first_name AS name FROM employees;
annual_salary.SELECT salary * 12 AS annual_salary FROM employees;
SELECT last_name AS "Last Name" FROM employees;
This query selects the first three employees, renaming first_name to Name and salary to MonthlySalary.
SELECT first_name AS Name, salary AS MonthlySalary FROM employees LIMIT 3;
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.
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.
AS in an SQL query when selecting columns?AS in SQL SELECTAS keyword is used to give a temporary name (alias) to a column or expression in the output.AS does in the query resultAS to alias the column price as cost?AS between the original column name and the alias.AS properly: price AS cost. Others use invalid keywords or operators.employees with columns first_name and last_name, what will be the output column name of this query?SELECT first_name AS fname, last_name AS lname FROM employees;
AS keyword renames the output columns to the alias names given.first_name and last_name are aliased as fname and lname respectively.SELECT product_name AS, price FROM products;
AS keyword must be followed by the alias name immediately.product_name AS is incomplete because no alias name is given after AS.sales table with column amount. Which query correctly sums the amounts and shows the result with the column name Total_Sales?SUM(amount) using AS or by just placing the alias after the expression.AS with underscore alias, valid.AS but alias after expression is valid.AS with quoted alias, also valid in many SQL dialects.Pass the test and this pattern moves unknown