i
SQL Select, Select distinct
Select Distinct Clause
SQL Where Clause
SQL And, Or, Not
SQL Aliases
SQL Like
SQL In
SQL Between
Order By Clause
Aggregate Functions (Min, Max, Avg, Sum, Count)
Count
AVG() Syntax
SUM
MIN
MAX
Group By
HAVING Clause
SQL Insert Into
SQL Create Table
SQL Drop Table
SQL Alter Table
SQL Constraints
SQL Not Null
SQL Unique
SQL Primary Key
SQL Foreign Key
SQL Default
Aliases are giving a temporary name to a column in a table or table itself. But it exists only while the query is executing.
Consider the below EMPLOYEE table
EMPLOYEE_ID |
FIRST_NAME |
LAST_NAME |
|
SALARY |
100 |
Steven |
King |
SKING |
24000 |
101 |
Neena |
Kochhar |
NKOCHHAR |
17000 |
102 |
Lex |
De Haan |
LDEHAAN |
17000 |
103 |
Alexander |
Hunold |
AHUNOLD |
9000 |
104 |
Bruce |
Ernst |
BERNST |
6000 |
105 |
David |
Austin |
DAUSTIN |
4800 |
106 |
Valli |
Pataballa |
VPATABAL |
4800 |
107 |
Diana |
Lorentz |
DLORENTZ |
4200 |
108 |
Nancy |
Greenberg |
NGREENBE |
12008 |
109 |
Daniel |
Faviet |
DFAVIET |
9000 |
In the below example, the select clause uses an arithmetic expression like salary/2 as an attribute,
Select first_name, salary/2
From employees
Where salary = 17000;
It displays the result-set as follows,
FIRST_NAME |
SALARY/2 |
Neena |
8500 |
Lex |
8500 |
Here replace the salary/2 attribute name to Half_Salary by using aliases.
Example,
Select first_name, salary/2 as Half_Salary
From employees
Where salary = 17000;
FIRST_NAME |
HALF_SALARY |
Neena |
8500 |
Lex |
8500 |
Here notice the change in column name from salary/2 to Half_salary after using aliases. We can also give a temporary name to the table, which helps to reduce the coding error.
Don't miss out!