Aliases in SQL

To make column names or table names more readable, we can use aliases:

SQL

SELECT e.first_name, e.last_name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;

In this query, e and d are aliases for the employees and departments tables, respectively.

In SQL, aliases are used to give a table or a column a temporary name. This can make your SQL queries more readable and can also be useful when you need to perform operations on the same table or column more than once within a query. Aliases are created using the AS keyword, but it is optional and often omitted.

Column Alias A column alias allows you to rename a column in the result set. Example:

SQL

SELECT first_name AS fname, last_name AS lname, email
FROM employees;

In this example:

Table Alias A table alias allows you to give a table a temporary name, which is useful for shortening table names or for self-joins. Example:

SQL

SELECT e.first_name, e.last_name, e.email
FROM employees AS e;

In this example: