What is an ALIAS command?

A table or column may be given a ALIAS name. To identify the table or column, use this alias name in the WHERE clause.

Example:

Employee Table

emp_id emp_name salary dept_id manager_id
E1 Rahul 15000 D1 M1
E2 Manoj 15000 D1 M1
E3 James 55000 D2 M2
E4 Michael 25000 D2 M2
E5 Ali 20000 D10 M3
E6 Robin 35000 D10 M3

Department Table

dept_id dept_name
D1 IT
D2 HR
D3 Finance
D4 Admin

Alias For Table

SELECT e.dept_id, d.dept_id,d.dept_name,e.emp_name
FROM Employee as e, Department as d
WHERE e.dept_id=d.dept_id;

Here, e refers to the alias name for the Employee table, and d refers to the alias name for the Department table.

Alias For Column

SELECT emp_name as 'Employee Name' FROM Employee;

Output

Employee Name
Rahul
Manoj
James
Michael
Ali
Robin

Here, Employee Name refers to the alias name for the emp_name column.

Code Runner

Copy the below queries in the code runner to see the result

SELECT e.dept_id, d.dept_id,d.dept_name,e.emp_name
FROM Employee as e, Department as d
WHERE e.dept_id=d.dept_id; 
SELECT emp_name as 'Employee Name' FROM Employee;