English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
You can temporarily rename a table or column by providing another name (ALIAS). The use of table aliases means renaming the table in a specific SQLite statement. Renaming is a temporary change, and the actual table name in the database will not change.
Column aliases are used to rename table columns for specific SQLite queries.
Here istableBasic Syntax of Aliases.
SELECT column1, column2.... FROM table_name AS alias_name WHERE [condition];
Here iscolumnBasic Syntax of Aliases.
SELECT column_name AS alias_name FROM table_name WHERE [condition];
Consider the following two tables, (a) The COMPANY table is as follows-
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 the department--
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
Now, here isTABLE ALIASThe usage of C and D as aliases for the COMPANY and DEPARTMENT tables-
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 statement will produce the following result-
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 usage example:COLUMN ALIASwhere COMPANY_ID is an alias for the ID column, and COMPANY_NAME is an alias for the name column.
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 statement will produce the following result-
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