You can rename a table or a section incidentally by giving another name, which is known as ALIAS. The utilization of table nom de plumes intends to rename a table in a specific PostgreSQL explanation. Renaming is a transitory change and the real table name doesn't change in the information base.
The segment false names are utilized to rename a table's sections with the end goal of a specific PostgreSQL inquiry.
Syntax
The fundamental linguistic structure of table false name is as per the following −
SELECT column1, column2....
FROM table_name AS alias_name
WHERE [condition];
The essential linguistic structure of section nom de plume is as per the following −
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 −
testdb=# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
(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
(7 rows)
Presently, following is the use of TABLE ALIAS where we utilize C and D as nom de plumes for COMPANY and DEPARTMENT tables, individually −
testdb=# SELECT C.ID, C.NAME, C.AGE, D.DEPT
FROM COMPANY AS C, DEPARTMENT AS D
WHERE C.ID = D.EMP_ID;
The above given PostgreSQL articulation will deliver the accompanying outcome −
id | name | age | dept
----+-------+-----+------------
1 | Paul | 32 | IT Billing
2 | Allen | 25 | Engineering
7 | James | 24 | Finance
3 | Teddy | 23 | Engineering
4 | Mark | 25 | Finance
5 | David | 27 | Engineering
6 | Kim | 22 | Finance
(7 rows)
Allow us to see a model for the use of COLUMN ALIAS where COMPANY_ID is a pseudonym of ID segment and COMPANY_NAME is a moniker of name section −
testdb=# 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 given PostgreSQL explanation will create the accompanying outcome −
company_id | company_name | age | dept
------------+--------------+-----+------------
1 | Paul | 32 | IT Billing
2 | Allen | 25 | Engineering
7 | James | 24 | Finance
3 | Teddy | 23 | Engineering
4 | Mark | 25 | Finance
5 | David | 27 | Engineering
6 | Kim | 22 | Finance
(7 rows)