1. Introduction
The MySQL AS keyword is used to assign aliases (alternative names) to tables and columns within a query.
This feature not only improves the readability of SQL statements but also helps express complex queries more concisely.
In this article, we will explain everything from the basic usage of AS to practical examples and important considerations.
To ensure beginners can easily understand the concept, we will include clear and concrete code examples throughout.
2. Basic Usage of the “AS” Keyword
2.1. Assigning an Alias to a Column
In MySQL, you can assign an alias to a column to use a more descriptive or readable column name.
The basic syntax is as follows:
SELECT column_name AS alias_name FROM table_name;Example
For example, if you want to concatenate first_name and last_name from the users table and assign the alias full_name:
SELECT first_name, last_name, CONCAT(first_name, ' ', last_name) AS full_name FROM users;When you execute this SQL statement, a column named full_name will be created, displaying the combined values of first_name and last_name.
2.2. Assigning an Alias to a Table
You can also assign aliases to tables.
This allows you to shorten long table names and improve the readability of complex queries.
The basic syntax is as follows:
SELECT t1.column_name FROM table_name AS t1;Example
For example, to assign the alias e to the employees table:
SELECT e.id, e.name FROM employees AS e;By using this approach, you can write SQL statements more concisely by using e instead of employees.

3. Why Use the “AS” Keyword?
3.1. Improving Query Readability
Using AS makes queries easier to understand intuitively.
It is especially useful when column names are long or when handling calculated results as columns.
3.2. Avoiding Ambiguity When Joining Multiple Tables
When using JOIN, if the same column name exists in multiple tables, ambiguity can occur.
In such cases, assigning aliases to tables helps prevent confusion.
SELECT e.name, d.department_name FROM employees AS e JOIN departments AS d ON e.department_id = d.id;In this query, the employees table is shortened to e, and the departments table is shortened to d, making the query more readable.
3.3. Assigning Aliases to Calculated Columns or Function Results
By assigning an alias to calculation results or function outputs in SQL, you can produce clearer and more understandable output.
SELECT price * quantity AS total_cost FROM orders;In this query, the result of price * quantity is given the descriptive name total_cost.
4. Practical Examples
4.1. Using “AS” in Multi-Table Joins
When joining different tables, assigning aliases helps shorten and simplify the query.
SELECT u.id, u.name, o.order_date
FROM users AS u
JOIN orders AS o ON u.id = o.user_id;In this example, the users table is defined as u, and the orders table is defined as o, eliminating redundant descriptions.
4.2. Assigning an Alias to a Calculated Result
When calculating a total amount, assigning an alias makes the output easier to understand.
SELECT product_name, price * quantity AS total_price FROM sales;As a result, the total_price column contains the calculated value of price * quantity.
5. Important Notes
5.1. “AS” Is Optional, but Explicit Usage Is Recommended
In MySQL, AS can be omitted. However, for better readability and maintainability, it is recommended to write it explicitly.
SELECT first_name full_name FROM users; -- AS can be omitted
SELECT first_name AS full_name FROM users; -- Recommended5.2. Using Reserved Keywords as Aliases
If you use an SQL reserved keyword as an alias, you must enclose it in backticks.
SELECT column_name AS `key` FROM table_name;6. FAQ (Frequently Asked Questions)
Q1: Is it okay to omit “AS”?
A1: Yes, it can be omitted. However, for improved readability, it is recommended to use it explicitly.
Q2: Can I assign the same alias to both a table and a column?
A2: To avoid confusion, it is best to use different aliases for tables and columns.
Q3: Can an alias contain spaces?
A3: Yes, it is possible, but you must enclose it in double quotes "" or backticks.
SELECT column_name AS "My Custom Name" FROM table_name;Q4: Can I use “AS” to create a temporary table?
A4: The AS keyword itself is not used independently to create a temporary table.
To create a temporary table, use CREATE TEMPORARY TABLE.
CREATE TEMPORARY TABLE temp_table AS SELECT * FROM original_table;Q5: Can I use “AS” to create a view?
A5: Yes. When creating a view, you can use AS to define the view’s query.
CREATE VIEW sales_summary AS
SELECT product_name, SUM(price * quantity) AS total_sales FROM sales GROUP BY product_name;7. Summary
In this article, we explained the MySQL AS keyword in detail.
The key points are as follows:
- Using
ASallows you to assign clear and descriptive aliases to columns and tables. - It improves query readability and makes SQL easier to understand.
- When using reserved keywords as aliases, you must enclose them in backticks.
The AS keyword is a highly useful feature when working with MySQL.
Use it effectively to write clean, efficient, and readable SQL queries!


