Just wondering ... I've seen aliasing written in four different ways.
3) column1 c
4) column1 AS c
Why so many variations and are these all equally usable or are there pros and cons to each?
1) this is either a table name or table alias prefixing the column name. It is not an alias of the column name.
2) this is the same as 1)
3) this is an alias of the column name
4) this is the same as 3 but including the optional "AS" keyword.
So there are only 2 types of alias... table aliases and column aliases.
A table alias can be defined after the table (or subquery) name in the query, and is then used as a prefix to the columns selected where there could possibly be ambiguity as to which column is required (where more than one table has the same named column). When defining a table alias it cannot use the "AS" keyword, that is only for column aliases.
Column aliases provide an alternative name for the column, and are defined in the SQL projection after each column as required. They may include the optional "AS" keyword. This is useful when you are querying more than one column of the same name and need to differentiate between them.
1 and 2 are examples of explicit scope. Instead of only providing a column reference, a reference to the object (via the object's actual name, or an alias for the object) is given.
Explicit scope in the SQL language is often a good thing - but can also be a problem when abstraction is done at SQL level. So treat it as a two edge sword and make a concious decision as to when it should be used, and when not.
3 and 4 are examples of naming a SQL projection column.