Introduction
Column aliases let you give a temporary new name to a column in your query result. This makes the output easier to read and understand.
Column aliases let you give a temporary new name to a column in your query result. This makes the output easier to read and 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 `order date` AS order_date FROM orders;
This creates a simple employees table, inserts two rows, and selects the first name and yearly salary with aliases.
CREATE TABLE employees (id INT, first_name VARCHAR(20), salary INT); INSERT INTO employees VALUES (1, 'Alice', 3000), (2, 'Bob', 4000); SELECT first_name AS employee_name, salary * 12 AS yearly_salary FROM employees;
Aliases only change the column name in the output, not in the actual table.
Use aliases to make your query results clearer for others reading them.
Column aliases rename columns temporarily in query results.
They improve readability and clarity of output.
Use AS keyword or just a space to assign an alias.
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 lname FROM employees;AS fname for first_name and a space alias lname for last_name.fname and lname.SELECT name AS, age FROM users;sales table with column amount. Which query correctly shows the total as Total_Sales and also calculates average sales as Avg_Sales?Pass the test and this pattern moves unknown