The meaning of an alias is to give a nickname to something. In Teradata also, we can give an alias to any column. Sometimes, the column’s name looks strange and not reader-friendly. In order to make it reader-friendly, we can make use of Teradata Alias.
Apart from the result set, an alias makes the SQL easier to write. The new alias name can be used anywhere in the SQL statement. We can give alias names to any other objects like tables and views to make it easier to write join queries.
Alias in Teradata syntax
select column1 alias1, column2 alias2,...,columnN aliasN from DatabaseName.TableName;
OR
select column1 as alias1, column2 as alias2,...,columnN as aliasN from DatabaseName.TableName;
Alias in Teradata example
The following example shows how to use the alias for columns in Teradata.
SELECT EMPNO EMPID, FIRST_NAME "FIRST NAME", LAST_NAME "LAST NAME" FROM TUTORIALSBOOK.Employee ORDER BY 1;
Output:
SELECT EMPNO EMPID, FIRST_NAME "FIRST NAME", LAST_NAME "LAST NAME"
FROM TUTORIALSBOOK.Employee
ORDER BY 1;
*** Query completed. 8 rows found. 3 columns returned.
*** Total elapsed time was 1 second.
EMPID FIRST NAME LAST NAME
----------- ------------------------- -------------------------
1001 STEFAN SALVATORE
1002 DIANA LORANCE
1003 JAMES MADISON
1004 JONES NICK
1005 LUCY GILLER
1006 ISSAC STEFAN
1007 NANCY GILBERT
1008 JOHN SMITH