Sql ALIASES

Sql ALIASES

Blog Bustle 29/03/2020

Sql aliases are used to give a temporary name to sql tables or columns in sql table. By Sql aliases, we can give short and readable name to columns or tables. We can give temporary name to every column or table.

Sql Aliases Syntax

Sql Aliases Syntax for column

SELECT column_1 AS alias_name
from table_name;

Sql Aliases Syntax for table

SELECT column_1
from table_name AS alias_name;

Sql Aliases Examples

Let's look at some examples to understand sql aliases.

I have two tables named employee and employee_salary.

id name city_name country
1 justin New york US
2 robin Binghamton US
3 jessie Nottingham England
4 chris Manchester England
id emp_id emp_salary
1 1 30000
2 2 40000
3 3 45000
4 4 50000

Find name and city of those employees who belong to US and sql query will be

SELECT name,city_name AS city
from employee
WHERE country = 'US';

After running this sql query, result will be

name city
justin New york
robin Binghamton

Find name and salary of those employees who belong to England and sql query will be

SELECT e.name,s.emp_salary AS salary
from employee AS e
INNER JOIN employee_salary AS s
ON e.id = s.emp_id
WHERE e.country = 'England';

After running this sql query, result will be

name salary
jessie 45000
chris 50000

After looking at these examples, we can easily understand and use sql aliases. Hope you like this tutorial.

Other important links

Sql Group By clause

Sql Limit clause

Sql Order By clause

Sql Aggregate Functions

Sql IN operator

Sql ALIASES searches:

Tags: #mysql