MySQL Aliases

Last Updated: March 12, 2022

You can give a temporary name for tables or columns inside the query so that you can easily read them.

Aliases are created with AS the keyword and it exists during the execution of the query.

Alias table syntax

SELECT column_name AS alias_name
FROM table_name;

Alias column syntax

SELECT column_name(s)
FROM table_name AS alias_name;

Examples

SELECT employees_id AS id FROM employees WHERE id = 3

Column alias is very usefull in WHERE clause

SELECT emp.name, dept.name  FROM employees AS emp, department AS dept
WHERE emp.department_id = dept.id
Test