You can rename a table or a segment incidentally by giving another name, which is known as ALIAS. The utilization of table assumed names intends to rename a table in a specific SQLite explanation. Renaming is a brief change and the real table name doesn't change in the data set.
The section assumed names are utilized to rename a table's segments with the end goal of a specific SQLite question.
Syntax
Following is the essential sentence structure of table assumed name.
SELECT column1, column2....
FROM table_name AS alias_name
WHERE [condition];
Following is the essential sentence structure of segment moniker.
SELECT column_name AS alias_name
FROM table_name
WHERE [condition];
Example
Think about the accompanying two tables, (a) COMPANY table is as per the following −
sqlite> select * from COMPANY;
ID NAME AGE ADDRESS SALARY
---------- -------------------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
(b) Another table is DEPARTMENT as follows −
ID DEPT EMP_ID
---------- -------------------- ----------
1 IT Billing 1
2 Engineering 2
3 Finance 7
4 Engineering 3
5 Finance 4
6 Engineering 5
7 Finance 6
Presently, following is the utilization of TABLE ALIAS where we utilize C and D as pseudonyms for COMPANY and DEPARTMENT tables individually −
sqlite> SELECT C.ID, C.NAME, C.AGE, D.DEPT
FROM COMPANY AS C, DEPARTMENT AS D
WHERE C.ID = D.EMP_ID;
The above SQLite proclamation will create the accompanying outcome −
ID NAME AGE DEPT
---------- ---------- ---------- ----------
1 Paul 32 IT Billing
2 Allen 25 Engineering
3 Teddy 23 Engineering
4 Mark 25 Finance
5 David 27 Engineering
6 Kim 22 Finance
7 James 24 Finance
Consider a model for the use of COLUMN ALIAS where COMPANY_ID is a moniker of ID section and COMPANY_NAME is a pseudonym of name segment.
sqlite> SELECT C.ID AS COMPANY_ID, C.NAME AS COMPANY_NAME, C.AGE, D.DEPT
FROM COMPANY AS C, DEPARTMENT AS D
WHERE C.ID = D.EMP_ID;
The above SQLite articulation will create the accompanying outcome −
COMPANY_ID COMPANY_NAME AGE DEPT
---------- ------------ ---------- ----------
1 Paul 32 IT Billing
2 Allen 25 Engineering
3 Teddy 23 Engineering
4 Mark 25 Finance
5 David 27 Engineering
6 Kim 22 Finance
7 James 24 Finance