You can set table aliases in SQL typing the identifier right after the table name.
SELECT * FROM table t1;
You can even use the keyword
There is no difference between both statements above. AS is just a more explicit way of mentioning the alias
The use is more obvious if you don't use 'SELECT *' (which is a bad habit you should get out of):
SELECT t1.colA, t2.colB, t3.colC FROM alongtablename AS t1, anotherlongtablename AS t2, yetanotherlongtablename AS t3 WHERE t1.colD = t2.colE...
The AS
in this case is an optional keyword defined in ANSI SQL 92 to define a <<correlation name>
,commonly known as alias for a table.
<table reference> ::= <table name> [ [ AS ] <correlation name> [ <left paren> <derived column list> <right paren> ] ] | <derived table> [ AS ] <correlation name> [ <left paren> <derived column list> <right paren> ] | <joined table> <derived table> ::= <table subquery> <derived column list> ::= <column name list> <column name list> ::= <column name> [ { <comma> <column name> }... ] Syntax Rules 1) A <correlation name> immediately contained in a <table refer- ence> TR is exposed by TR. A <table name> immediately contained in a <table reference> TR is exposed by TR if and only if TR does not specify a <correlation name>.
It seems a best practice NOT to use the AS
keyword for table aliases as it is not supported by a number of commonly used databases.