Sql Aliases
SQL Aliases:-





- SQL Aliases are used to give a table, or a column in a table, a temporary name.
- The use of table aliases is to rename a table in a specific SQL statement.
- The renaming is a temporary change and the actual table name does not change in the database.
- Aliases are often used to make column names more readable.
- An alias only exists for the duration of the query.
Alias Column Syntax:-
SELECT column_name AS alias_name
FROM table_name
WHERE condition;
Alias Table Syntax:-
SELECT column1 , column2 , ...
FROM table_name AS alias_name
WHERE condition;
Alias Column Example:-
Consider the table STUDENT having the following records:-
SELECT StudentID AS ID, Hometown AS Address
FROM STUDENT
WHERE Age>22 ;
OUTPUT:-
Alias Table Example:-
Consider two tables having the following records:-
STUDENT TABLE:-
DEPARTMENTS TABLE:-
In the below query we use Alias for table STUDENT is "O" and for the table DEPARTMENTS is "D".
Now we want to Select STUDENTID, NAME, AGE, From STUDENT Table and department Name, DEPTID from DEPARTMENTS table where STUDENTID FROM STUDENT table is equal to STDID FROM DEPARTMENTS table.
SELECT S.STUDENTID, S.Name, S.Age, D.Name, D.DEPTID
FROM STUDENT S, DEPARTMENTS D
WHERE S.STUDENTID = D.StdID;
OUTPUT:-
Comments
Post a Comment