
SELECT COUNT(*) AS TotalEmployees FROM Employee Here we are giving the alias as TotalEmployees to the COUNT(*) function. To make the result set more readable we can give an alias for the same as shown in the below SQL statement. Now execute the above SQL statement, you will get the total number of employees in the employee table and you will get the below output.īut notice that in this case, the column name is COUNT(*) which is the function name, which doesn’t make any sense for the result set. Following is the SQL statement which will give you the total number of employees present in the employee table.

Let’s execute another SQL statement to display the total number of employees in the table.

Note: Alias’s use is more common in joins, where we prefix alias and dot to a column name to avoid conflicts of two similar column names from two different tables. When you execute the above query, you will get the below result set. SELECT emp.Name, emp.Department, emp.age, emp.Salary FROM Employee AS emp Notice that here we used emp.Name and emp.Department, etc. emp to the employee table and then using the alias name we are accessing the column names. In the below SQL Statement, we have given an alias i.e. INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1010, 'Hina Sharma', 'HR', 75000, 'Female', 26, 'Mumbai') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1009, 'Pranaya Kumar', 'IT', 50000, 'Male', 28, 'London') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1008, 'Sambit Mohanty', 'IT', 50000, 'Male', 28, 'London') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1007, 'Priyanla Dewangan', 'HR', 45000, 'Female', 27, 'Mumbai') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1006, 'Anurag Mohanty', 'IT', 35000, 'Male', 25, 'London') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1005, 'Linda Jones', 'HR', 75000, 'Female', 26, 'Mumbai') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1004, 'Mike Walker', 'Finance', 50000, 'Male', 28, 'London') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1003, 'James Brown', 'Finance', 50000, 'Male', 28, 'Delhi') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1002, 'Mary Smith', 'HR', 45000, 'Female', 27, 'Mumbai') INSERT INTO employee (Id, `Name`, Department, Salary, Gender, Age, City) VALUES (1001, 'John Doe', 'IT', 35000, 'Male', 25, 'London') Please use the following SQL Script to create the company database and employee table with the required records. We are going to use the following Employee table to understand Aliases in MySQL with Examples. The AS keyword is used to define the Alias in SQL statement.

Also, if the table names or column names are big or not readable. The Aliases are more useful when multiple columns or multiple tables are used in a single query. The purpose of Aliases is to make table or column names more readable. In MySQL, an Alias means a temporary name given to a table or a column. Please read our previous article where we discussed the LIMIT Clause in MySQL with Examples. In this article, I am going to discuss Alias in MySQL with Examples. Data Structures and Algorithms Tutorialsīack to: MySQL Tutorials for Beginners and Professionals Alias in MySQL with Examples.
